home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / utils / speedbar.el.z / speedbar.el
Encoding:
Text File  |  1998-05-21  |  95.2 KB  |  2,525 lines

  1. ;;; speedbar --- quick access to files and tags -*-byte-compile-warnings:nil;-*-
  2.  
  3. ;; Copyright (C) 1996, 1997 Eric M. Ludlam
  4. ;;
  5. ;; Author: Eric M. Ludlam <zappo@gnu.ai.mit.edu>
  6. ;; Version: 0.5
  7. ;; Keywords: file, tags, tools
  8. ;; X-RCS: $Id: speedbar.el,v 1.52 1997/06/06 23:10:28 zappo Exp $
  9. ;;
  10. ;; This program is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14. ;;
  15. ;; This program is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;; GNU General Public License for more details.
  19. ;;
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with this program; if not, you can either send email to this
  22. ;; program's author (see below) or write to:
  23. ;;
  24. ;;              The Free Software Foundation, Inc.
  25. ;;              675 Mass Ave.
  26. ;;              Cambridge, MA 02139, USA.
  27. ;;
  28. ;; Please send bug reports, etc. to zappo@gnu.ai.mit.edu.
  29. ;;
  30.  
  31. ;;; Commentary:
  32. ;;
  33. ;;   The speedbar provides a frame in which files, and locations in
  34. ;; files are displayed.  These items can be clicked on with mouse-2
  35. ;; in order to make the last active frame display that file location.
  36. ;;
  37. ;;   To use speedbar, add this to your .emacs file:
  38. ;;
  39. ;;   (autoload 'speedbar-frame-mode "speedbar" "Popup a speedbar frame" t)
  40. ;;   (autoload 'speedbar-get-focus "speedbar" "Jump to speedbar frame" t)
  41. ;;
  42. ;;   If you want to choose it from a menu or something, do this:
  43. ;;
  44. ;;   (define-key-after (lookup-key global-map [menu-bar tools])
  45. ;;      [speedbar] '("Speedbar" . speedbar-frame-mode) [calendar])
  46. ;;
  47. ;;   If you want to access speedbar using only the keyboard, do this:
  48. ;;
  49. ;;   (define-key global-map [f4] 'speedbar-get-focus)
  50. ;;
  51. ;;   This will let you hit f4 (or whatever key you choose) to jump
  52. ;; focus to the speedbar frame.  Pressing RET or e to jump to a file
  53. ;; or tag will move you back to the attached frame.  The command
  54. ;; `speedbar-get-fucus' will also create a speedbar frame if it does
  55. ;; not exist.
  56. ;;
  57. ;;   Once a speedbar frame is active, it takes advantage of idle time
  58. ;; to keep it's contents updated.  The contents is usually a list of
  59. ;; files in the directory of the currently active buffer.  When
  60. ;; applicable, tags in the active file can be expanded.
  61. ;;
  62. ;;   To add new supported files types into speedbar, use the function
  63. ;; `speedbar-add-supported-extension' If speedbar complains that the
  64. ;; file type is not supported, that means there is no built in
  65. ;; support from imenu, and the etags part wasn't set up correctly.  You
  66. ;; may add elements to `speedbar-supported-extension-expressions' as long
  67. ;; as it is done before speedbar is loaded.
  68. ;;
  69. ;;   To prevent speedbar from following you into certain directories
  70. ;; use the function `speedbar-add-ignored-path-regexp' too add a new
  71. ;; regular expression matching a type of path.  You may add list
  72. ;; elements to `speedbar-ignored-path-expressions' as long as it is
  73. ;; done before speedbar is loaded.
  74. ;;
  75. ;;   To add new file types to imenu, see the documentation in the
  76. ;; file imenu.el that comes with emacs.  To add new file types which
  77. ;; etags supports, you need to modify the variable
  78. ;; `speedbar-fetch-etags-parse-list'.
  79. ;;
  80. ;;    If the updates are going too slow for you, modify the variable
  81. ;; `speedbar-update-speed' to a longer idle time before updates.
  82. ;;
  83. ;;    If you navigate directories, you will probably notice that you
  84. ;; will navigate to a directory which is eventually replaced after
  85. ;; you go back to editing a file (unless you pull up a new file.)
  86. ;; The delay time before this happens is in
  87. ;; `speedbar-navigating-speed', and defaults to 10 seconds.
  88. ;;
  89. ;;    XEmacs users may want to change the default timeouts for
  90. ;; `speedbar-update-speed' to something longer as XEmacs doesn't have
  91. ;; idle timers, the speedbar timer keeps going off arbitrarilly while
  92. ;; you're typing.  It's quite pesky.
  93. ;;
  94. ;;    Users of emacs previous to to v 19.31 (when idle timers
  95. ;; where introduced) will not have speedbar updating automatically.
  96. ;; Use "r" to refresh the display after changing directories.
  97. ;; Remember, do not interrupt the stealthy updates or you display may
  98. ;; not be completely refreshed.
  99. ;;
  100. ;;    See optional file `speedbspec.el' for additional configurations
  101. ;; which allow speedbar to create specialized lists for special modes
  102. ;; that are not file-related.
  103. ;;
  104. ;;    See optional file `speedbcfg.el' for interactive buffers
  105. ;; allowing simple configuration of colors and features of speedbar.
  106. ;;
  107. ;;    AUC-TEX users: The imenu tags for AUC-TEX mode don't work very
  108. ;; well.  Use the imenu keywords from tex-mode.el for better results.
  109. ;;
  110. ;; This file requires the library package assoc (association lists)
  111.  
  112. ;;; Speedbar updates can be found at:
  113. ;; ftp://ftp.ultranet.com/pub/zappo/speedbar*.tar.gz
  114. ;;
  115.  
  116. ;;; Change log:
  117. ;; 0.1   Initial Revision
  118. ;; 0.2   Fixed problem with x-pointer-shape causing future frames not
  119. ;;         to be created.
  120. ;;       Fixed annoying habit of `speedbar-update-contents' to make
  121. ;;         it possible to accidentally kill the speedbar buffer.
  122. ;;       Clicking directory names now only changes the contents of
  123. ;;         the speedbar, and does not cause a dired mode to appear.
  124. ;;         Clicking the <+> next to the directory does cause dired to
  125. ;;         be run.
  126. ;;       Added XEmacs support, which means timer support moved to a
  127. ;;         platform independant call.
  128. ;;       Added imenu support.  Now modes are supported by imenu
  129. ;;         first, and etags only if the imenu call doesn't work.
  130. ;;         Imenu is a little faster than etags, and is more emacs
  131. ;;         friendly.
  132. ;;       Added more user control variables described in the commentary.
  133. ;;       Added smart recentering when nodes are opened and closed.
  134. ;; 0.3   x-pointer-shape fixed for emacs 19.35, so I put that check in.
  135. ;;       Added invisible codes to the beginning of each line.
  136. ;;       Added list aproach to node expansion for easier addition of new
  137. ;;         types of things to expand by
  138. ;;       Added multi-level path name support
  139. ;;       Added multi-level tag name support.
  140. ;;       Only mouse-2 is now used for node expansion
  141. ;;       Added keys e + - to edit expand, and contract node lines
  142. ;;       Added longer legal file regexp for all those modes which support
  143. ;;         imenu. (pascal, fortran90, ada, pearl)
  144. ;;       Added pascal support to etags from Dave Penkler <dave_penkler@grenoble.hp.com>
  145. ;;       Fixed centering algorithm
  146. ;;       Tried to choose background independent colors.  Made more robust.
  147. ;;       Rearranged code into a more logical order
  148. ;; 0.3.1 Fixed doc & broken keybindings
  149. ;;       Added mode hooks.
  150. ;;       Improved color selection to be background mode smart
  151. ;;       `nil' passed to `speedbar-frame-mode' now toggles the frame as
  152. ;;         advertised in the doc string
  153. ;; 0.4a  Added modified patch from Dan Schmidt <dfan@lglass.com> allowing a
  154. ;;         directory cache to be maintained speeding up revisiting of files.
  155. ;;       Default raise-lower behavior is now off by default.
  156. ;;       Added some menu items for edit expand and contract.
  157. ;;       Pre 19.31 emacsen can run without idle timers.
  158. ;;       Added some patch information from Farzin Guilak <farzin@protocol.com>
  159. ;;         adding xemacs specifics, and some etags upgrades.
  160. ;;       Added ability to set a faces symbol-value to a string
  161. ;;         representing the desired foreground color.  (idea from
  162. ;;         Farzin Guilak, but implemented differently)
  163. ;;       Fixed problem with 1 character buttons.
  164. ;;       Added support for new Imenu marker technique.
  165. ;;       Added `speedbar-load-hooks' for things to run only once on
  166. ;;         load such as updating one of the many lists.
  167. ;;       Added `speedbar-supported-extension-expressions' which is a
  168. ;;         list of extensions that speedbar will tag.  This variable
  169. ;;         should only be updated with `speedbar-add-supported-extension'
  170. ;;       Moved configure dialog support to a separate file so
  171. ;;         speedbar is not dependant on eieio to run
  172. ;;       Fixed list-contraction problem when the item was at the end
  173. ;;         of a sublist.
  174. ;;       Fixed XEmacs multi-frame timer selecting bug problem.
  175. ;;       Added `speedbar-ignored-modes' which is a list of major modes
  176. ;;         speedbar will not follow when it is displayed in the selected frame
  177. ;; 0.4   When the file being edited is not in the list, and is a file
  178. ;;         that should be in the list, the speedbar cache is replaced.
  179. ;;       Temp buffers are now shown in the attached frame not the
  180. ;;         speedbar frame
  181. ;;       New variables `speedbar-vc-*' and `speedbar-stealthy-function-list'
  182. ;;         added.  `speedbar-update-current-file' is now a member of
  183. ;;         the stealthy list.  New function `speedbar-check-vc' will
  184. ;;         examine each file and mark it if it is checked out.  To
  185. ;;         add new version control types, override the function
  186. ;;         `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'.
  187. ;;         The stealth list is interruptible so that long operations
  188. ;;         do not interrupt someones editing flow.  Other long
  189. ;;         speedbar updates will be added to the stealthy list in the
  190. ;;         future should interesting ones be needed.
  191. ;;       Added many new functions including:
  192. ;;         `speedbar-item-byte-compile' `speedbar-item-load'
  193. ;;         `speedbar-item-copy' `speedbar-item-rename' `speedbar-item-delete'
  194. ;;         and `speedbar-item-info'
  195. ;;       If the user kills the speedbar buffer in some way, the frame will
  196. ;;         be removed.
  197. ;; 0.4.1 Bug fixes
  198. ;;       <mark.jeffries@nomura.co.uk> added `speedbar-update-flag',
  199. ;;         XEmacs fixes for menus, and tag sorting, and quit key.
  200. ;;       Modeline now updates itself based on window-width.
  201. ;;       Frame is cached when closed to make pulling it up again faster.
  202. ;;       Speedbars window is now marked as dedicated.
  203. ;;       Added bindings: <grossjoh@charly.informatik.uni-dortmund.de>
  204. ;;       Long directories are now span multiple lines autmoatically
  205. ;;       Added `speedbar-directory-button-trim-method' to specify how to
  206. ;;         sorten the directory button to fit on the screen.
  207. ;; 0.4.2 Add one level of full-text cache.
  208. ;;       Add `speedbar-get-focus' to switchto/raise the speedbar frame.
  209. ;;       Editing thing-on-line will auto-raise the attached frame.
  210. ;;       Bound `U' to `speedbar-up-directory' command.
  211. ;;       Refresh will now maintain all subdirectories that were open
  212. ;;        when the refresh was requested.  (This does not include the
  213. ;;        tags, only the directories)
  214. ;; 0.4.3 Bug fixes
  215. ;; 0.4.4 Added `speedbar-ignored-path-expressions' and friends.
  216. ;;       Configuration menu items not displayed if dialog-mode not present
  217. ;;       Speedbar buffer now starts with a space, and is not deleted
  218. ;;        ewhen the speedbar frame is closed.  This prevents the invisible
  219. ;;        frame from preventing buffer switches with other buffers.
  220. ;;       Fixed very bad bug in the -add-[extension|path] functions.
  221. ;;       Added `speedbar-find-file-in-frame' which will always pop up a frame
  222. ;;        that is already display a buffer selected in the speedbar buffer.
  223. ;;       Added S-mouse2 as "power click" for always poping up a new frame.
  224. ;;        and always rescanning with imenu (ditching the imenu cache), and
  225. ;;        always rescanning directories.
  226. ;; 0.4.5 XEmacs bugfixes and enhancements.
  227. ;;       Window Title simplified.
  228. ;; 0.4.6 Fixed problems w/ dedicated minibuffer frame.
  229. ;;       Fixed errors reported by checkdoc.
  230. ;; 0.5   Mode-specific contents added.  Controlled w/ the variable
  231. ;;         `speedbar-mode-specific-contents-flag'.  See speedbspec
  232. ;;         for info on enabling this feature.
  233. ;;       `speedbar-load-hook' name change and pointer check against
  234. ;;         major-mode.  Suggested by Sam Steingold <sds@ptc.com>
  235. ;;       Quit auto-selects the attached frame.
  236. ;;       Ranamed `speedbar-do-updates' to `speedbar-update-flag'
  237. ;;       Passes checkdoc.
  238.  
  239. ;;; TODO:
  240. ;; 1) More functions to create buttons and options
  241. ;; 2) filtering algoritms to reduce the number of tags/files displayed.
  242. ;; 3) Timeout directories we haven't visited in a while.
  243. ;; 4) Remeber tags when refreshing the display.  (Refresh tags too?)
  244. ;; 5) More 'special mode support.
  245. ;; 6) Smart way to auto-expand instead of directory switch
  246.  
  247. ;;; Code:
  248. (require 'assoc)
  249. (require 'easymenu)
  250.  
  251. (defvar speedbar-xemacsp (string-match "XEmacs" emacs-version)
  252.   "Non-nil if we are running in the XEmacs environment.")
  253.  
  254. (defvar speedbar-initial-expansion-list
  255.   '(speedbar-directory-buttons speedbar-default-directory-list)
  256.   "List of functions to call to fill in the speedbar buffer.
  257. Whenever a top level update is issued all functions in this list are
  258. run.  These functions will always get the default directory to use
  259. passed in as the first parameter, and a 0 as the second parameter.
  260. The 0 indicates the uppermost indentation level.  They must assume
  261. that the cursor is at the position where they start inserting
  262. buttons.")
  263.  
  264. (defvar speedbar-stealthy-function-list
  265.   '(speedbar-update-current-file speedbar-check-vc)
  266.   "List of functions to periodically call stealthily.
  267. Each function must return nil if interrupted, or t if completed.
  268. Stealthy functions which have a single operation should always return
  269. t.  Functions which take a long time should maintain a state (where
  270. they are in their speedbar related calculations) and permit
  271. interruption.  See `speedbar-check-vc' as a good example.")
  272.  
  273. (defvar speedbar-mode-specific-contents-flag t
  274.   "*Non-nil means speedbar will show special-mode contents.
  275. This permits some modes to create customized contents for the speedbar
  276. frame.")
  277.  
  278. (defvar speedbar-special-mode-expansion-list nil
  279.   "Mode specific list of functions to call to fill in speedbar.
  280. Some modes, such as Info or RMAIL, do not relate quite as easily into
  281. a simple list of files.  When this variable is non-nil and buffer-local,
  282. then these functions are used, creating specialized contents.  These
  283. functions are called each time the speedbar timer is called.  This
  284. allows a mode to update its contents regularly.
  285.  
  286.   Each function is called with the default and frame belonging to
  287. speedbar, and with one parameter; the buffer requesting
  288. the speedbar display.")
  289.  
  290. (defvar speedbar-load-hook nil
  291.   "Hooks run when speedbar is loaded.")
  292.  
  293. (defvar speedbar-desired-buffer nil
  294.   "Non-nil when speedbar is showing buttons specific a special mode.
  295. In this case it is the originating buffer.")
  296.  
  297. (defvar speedbar-show-unknown-files nil
  298.   "*Non-nil show files we can't expand with a ? in the expand button.
  299. nil means don't show the file in the list.")
  300.  
  301. ;; XEmacs timers aren't based on idleness.  Therefore tune it down a little
  302. ;; or suffer mightilly!
  303. (defvar speedbar-update-speed (if speedbar-xemacsp 5 1)
  304.   "*Idle time in seconds needed before speedbar will update itself.
  305. Updates occur to allow speedbar to display directory information
  306. relevant to the buffer you are currently editing.")
  307. (defvar speedbar-navigating-speed 10
  308.   "*Idle time to wait after navigation commands in speedbar are executed.
  309. Navigation commands included expanding/contracting nodes, and moving
  310. between different directories.")
  311.  
  312. (defvar speedbar-frame-parameters (list
  313.                    ;; XEmacs fails to delete speedbar
  314.                    ;; if minibuffer is off.
  315.                    ;(cons 'minibuffer
  316.                    ; (if speedbar-xemacsp t nil))
  317.                    ;; The above behavior seems to have fixed
  318.                    ;; itself somewhere along the line.
  319.                    ;; let me know if any problems arise.
  320.                    '(minibuffer . nil)
  321.                    '(width . 20)
  322.                    '(scroll-bar-width . 10)
  323.                    '(border-width . 0)
  324.                    '(unsplittable . t) )
  325.   "*Parameters to use when creating the speedbar frame.
  326. Parameters not listed here which will be added automatically are
  327. `height' which will be initialized to the height of the frame speedbar
  328. is attached to.  To add more frame defaults, `cons' new alist members
  329. onto this variable through the `speedbar-load-hook'")
  330.  
  331. (defvar speedbar-use-imenu-flag (stringp (locate-library "imenu"))
  332.   "*Non-nil means use imenu for file parsing.  nil to use etags.
  333. XEmacs doesn't support imenu, therefore the default is to use etags
  334. instead.  Etags support is not as robust as imenu support.")
  335.  
  336. (defvar speedbar-sort-tags nil
  337.   "*If Non-nil, sort tags in the speedbar display.  (Etags only)
  338. See imenu.el source for how imenu does sorting.")
  339.  
  340. (defvar speedbar-directory-button-trim-method 'span
  341.   "*Indicates how the directory button will be displayed.
  342. Possible values are:
  343.  'span - span large directories over multiple lines.
  344.  'trim - trim large directories to only show the last few.
  345.  nil   - no trimming.")
  346.  
  347. (defvar speedbar-before-delete-hook nil
  348.   "*Hooks called before deleting the speedbar frame.")
  349.  
  350. (defvar speedbar-mode-hook nil
  351.   "*Hooks called after creating a speedbar buffer.")
  352.  
  353. (defvar speedbar-timer-hook nil
  354.   "*Hooks called after running the speedbar timer function.")
  355.  
  356. (defvar speedbar-verbosity-level 1
  357.   "*Verbosity level of the speedbar.  0 means say nothing.
  358. 1 means medium level verbosity.  2 and higher are higher levels of
  359. verbosity.")
  360.  
  361. (defvar speedbar-vc-indicator " *"
  362.   "*Text used to mark files which are currently checked out.
  363. Currently only RCS is supported.  Other version control systems can be
  364. added by examining the function `speedbar-this-file-in-vc' and
  365. `speedbar-vc-check-dir-p'")
  366.  
  367. (defvar speedbar-vc-do-check t
  368.   "*Non-nil check all files in speedbar to see if they have been checked out.
  369. Any file checked out is marked with `speedbar-vc-indicator'")
  370.  
  371. (defvar speedbar-vc-to-do-point nil
  372.   "Local variable maintaining the current version control check position.")
  373.  
  374. (defvar speedbar-ignored-modes nil
  375.   "*List of major modes which speedbar will not switch directories for.")
  376.  
  377. (defvar speedbar-ignored-path-expressions
  378.   '("/log/$")
  379.   "*List of regular expressions matching directories speedbar will ignore.
  380. They should included paths to directories which are notoriously very
  381. large and take a long time to load in.  Use the function
  382. `speedbar-add-ignored-path-regexp' to add new items to this list after
  383. speedbar is loaded.  You may place anything you like in this list
  384. before speedbar has been loaded.")
  385.  
  386. (defvar speedbar-file-unshown-regexp
  387.   (let ((nstr "") (noext completion-ignored-extensions))
  388.     (while noext
  389.       (setq nstr (concat nstr (regexp-quote (car noext)) "$"
  390.              (if (cdr noext) "\\|" ""))
  391.         noext (cdr noext)))
  392.     (concat nstr "\\|#[^#]+#$\\|\\.\\.?$"))
  393.   "*Regexp matching files we don't want displayed in a speedbar buffer.
  394. It is generated from the variable `completion-ignored-extensions'")
  395.  
  396. (defvar speedbar-supported-extension-expressions
  397.   (append '(".[CcHh]\\(++\\|pp\\|c\\|h\\)?" ".tex\\(i\\(nfo\\)?\\)?"
  398.         ".el" ".emacs" ".p" ".java")
  399.       (if speedbar-use-imenu-flag
  400.           '(".f90" ".ada" ".pl" ".tcl" ".m"
  401.         "Makefile\\(\\.in\\)?")))
  402.   "*List of regular expressions which will match files supported by tagging.
  403. Do not prefix the `.' char with a double \\ to quote it, as the period
  404. will be stripped by a simplified optimizer when compiled into a
  405. singular expression.  This variable will be turned into
  406. `speedbar-file-regexp' for use with speedbar.  You should use the
  407. function `speedbar-add-supported-extension' to add a new extension at
  408. runtime, or use the configuration dialog to set it in your .emacs
  409. file.")
  410.  
  411. (defun speedbar-extension-list-to-regex (extlist)
  412.   "Takes EXTLIST, a list of extensions and transforms it into regexp.
  413. All the preceding . are stripped for an optimized expression starting
  414. with . followed by extensions, followed by full-filenames."
  415.   (let ((regex1 nil) (regex2 nil))
  416.     (while extlist
  417.       (if (= (string-to-char (car extlist)) ?.)
  418.       (setq regex1 (concat regex1 (if regex1 "\\|" "")
  419.                    (substring (car extlist) 1)))
  420.     (setq regex2 (concat regex2 (if regex2 "\\|" "") (car extlist))))
  421.       (setq extlist (cdr extlist)))
  422.     ;; concat all the sub-exressions together, making sure all types
  423.     ;; of parts exist during concatination.
  424.     (concat "\\("
  425.         (if regex1 (concat "\\(\\.\\(" regex1 "\\)\\)") "")
  426.         (if (and regex1 regex2) "\\|" "")
  427.         (if regex2 (concat "\\(" regex2 "\\)") "")
  428.         "\\)$")))
  429.  
  430. (defvar speedbar-ignored-path-regexp
  431.   (speedbar-extension-list-to-regex speedbar-ignored-path-expressions)
  432.   "Regular expression matching paths speedbar will not switch to.
  433. Created from `speedbar-ignored-path-expressions' with the function
  434. `speedbar-extension-list-to-regex' (A misnamed function in this case.)
  435. Use the function `speedbar-add-ignored-path-regexp' to modify this
  436. variable.")
  437.  
  438. (defvar speedbar-file-regexp
  439.   (speedbar-extension-list-to-regex speedbar-supported-extension-expressions)
  440.   "Regular expression matching files we know how to expand.
  441. Created from `speedbar-supported-extension-expression' with the
  442. function `speedbar-extension-list-to-regex'")
  443.  
  444. (defun speedbar-add-supported-extension (extension)
  445.   "Add EXTENSION as a new supported extension for speedbar tagging.
  446. This should start with a `.' if it is not a complete file name, and
  447. the dot should NOT be quoted in with \\.  Other regular expression
  448. matchers are allowed however.  EXTENSION may be a single string or a
  449. list of strings."
  450.   (if (not (listp extension)) (setq extension (list extension)))
  451.   (while extension
  452.     (if (member (car extension) speedbar-supported-extension-expressions)
  453.     nil
  454.       (setq speedbar-supported-extension-expressions
  455.         (cons (car extension) speedbar-supported-extension-expressions)))
  456.     (setq extension (cdr extension)))
  457.   (setq speedbar-file-regexp (speedbar-extension-list-to-regex
  458.                   speedbar-supported-extension-expressions)))
  459.  
  460. (defun speedbar-add-ignored-path-regexp (path-expression)
  461.   "Add PATH-EXPRESSION as a new ignored path for speedbar tracking.
  462. This function will modify `speedbar-ignored-path-regexp' and add
  463. PATH-EXPRESSION to `speedbar-ignored-path-expressions'."
  464.   (if (not (listp path-expression))
  465.       (setq path-expression (list path-expression)))
  466.   (while path-expression
  467.     (if (member (car path-expression) speedbar-ignored-path-expressions)
  468.     nil
  469.       (setq speedbar-ignored-path-expressions
  470.         (cons (car path-expression) speedbar-ignored-path-expressions)))
  471.     (setq path-expression (cdr path-expression)))
  472.   (setq speedbar-ignored-path-regexp (speedbar-extension-list-to-regex
  473.                       speedbar-ignored-path-expressions)))
  474.  
  475. (defvar speedbar-update-flag (or (not (fboundp 'run-with-idle-timer))
  476.                    (not (fboundp 'start-itimer)))
  477.   "*Non-nil means to automatically update the display.
  478. When this is nil then speedbar will not follow the attached frame's path.
  479. When speedbar is active, use:
  480.  
  481. \\<speedbar-key-map> `\\[speedbar-toggle-updates]'
  482.  
  483. to toggle this value.")
  484.  
  485. (defvar speedbar-syntax-table nil
  486.   "Syntax-table used on the speedbar.")
  487.  
  488. (if speedbar-syntax-table
  489.     nil
  490.   (setq speedbar-syntax-table (make-syntax-table))
  491.   ;; turn off paren matching around here.
  492.   (modify-syntax-entry ?\' " " speedbar-syntax-table)
  493.   (modify-syntax-entry ?\" " " speedbar-syntax-table)
  494.   (modify-syntax-entry ?( " " speedbar-syntax-table)
  495.   (modify-syntax-entry ?) " " speedbar-syntax-table)
  496.   (modify-syntax-entry ?[ " " speedbar-syntax-table)
  497.   (modify-syntax-entry ?] " " speedbar-syntax-table))
  498.  
  499.  
  500. (defvar speedbar-key-map nil
  501.   "Keymap used in speedbar buffer.")
  502.  
  503. (autoload 'speedbar-configure-options "speedbcfg" "Configure speedbar variables" t)
  504. (autoload 'speedbar-configure-faces "speedbcfg" "Configure speedbar faces" t)
  505.  
  506. (if speedbar-key-map
  507.     nil
  508.   (setq speedbar-key-map (make-keymap))
  509.   (suppress-keymap speedbar-key-map t)
  510.  
  511.   ;; control
  512.   (define-key speedbar-key-map "e" 'speedbar-edit-line)
  513.   (define-key speedbar-key-map "\C-m" 'speedbar-edit-line)
  514.   (define-key speedbar-key-map "+" 'speedbar-expand-line)
  515.   (define-key speedbar-key-map "-" 'speedbar-contract-line)
  516.   (define-key speedbar-key-map "g" 'speedbar-refresh)
  517.   (define-key speedbar-key-map "t" 'speedbar-toggle-updates)
  518.   (define-key speedbar-key-map "q" 'speedbar-close-frame)
  519.   (define-key speedbar-key-map "U" 'speedbar-up-directory)
  520.  
  521.   ;; navigation
  522.   (define-key speedbar-key-map "n" 'speedbar-next)
  523.   (define-key speedbar-key-map "p" 'speedbar-prev)
  524.   (define-key speedbar-key-map " " 'speedbar-scroll-up)
  525.   (define-key speedbar-key-map "\C-?" 'speedbar-scroll-down)
  526.  
  527.   ;; After much use, I suddenly desired in my heart to perform dired
  528.   ;; style operations since the directory was RIGHT THERE!
  529.   (define-key speedbar-key-map "I" 'speedbar-item-info)
  530.   (define-key speedbar-key-map "B" 'speedbar-item-byte-compile)
  531.   (define-key speedbar-key-map "L" 'speedbar-item-load)
  532.   (define-key speedbar-key-map "C" 'speedbar-item-copy)
  533.   (define-key speedbar-key-map "D" 'speedbar-item-delete)
  534.   (define-key speedbar-key-map "R" 'speedbar-item-rename)
  535.  
  536.   (if (string-match "XEmacs" emacs-version)
  537.       (progn
  538.     ;; bind mouse bindings so we can manipulate the items on each line
  539.     (define-key speedbar-key-map 'button2 'speedbar-click)
  540.     (define-key speedbar-key-map '(shift button2) 'speedbar-power-click)
  541.     (define-key speedbar-key-map '(meta button3) 'speedbar-mouse-item-info)
  542.  
  543.     ;; Setup XEmacs Menubar w/ etags specific items
  544.     (defvar speedbar-menu
  545.       '("Speed Bar"
  546.         ["Run Speedbar" (speedbar-frame-mode 1) t]
  547.         ["Refresh" speedbar-refresh t]
  548.         ["Allow Auto Updates"
  549.          speedbar-toggle-updates
  550.          :style toggle
  551.          :selected speedbar-update-flag]
  552.         "-----"
  553.         ["Sort etags in Speedbar"
  554.          (speedbar-toggle-etags "sort")
  555.          :style toggle
  556.          :selected speedbar-sort-tags]
  557.         ["Show unknown files"
  558.          (speedbar-toggle-etags "show")
  559.          :style toggle
  560.          :selected speedbar-show-unknown-files]
  561.         "-----"
  562.         ["Use C++ Tagging"
  563.          (speedbar-toggle-etags "-C")
  564.          :style toggle
  565.          :selected (member "-C" speedbar-fetch-etags-arguments)]
  566.         ["Tag preprocessor defs"
  567.          (speedbar-toggle-etags "-D")
  568.          :style toggle
  569.          :selected (not (member "-D" speedbar-fetch-etags-arguments))]
  570.         ["Use indentation"
  571.          (speedbar-toggle-etags "-S")
  572.          :style toggle
  573.          :selected (not (member "-S" speedbar-fetch-etags-arguments))]))
  574.  
  575.     (add-submenu '("Tools") speedbar-menu nil)
  576.  
  577.     )
  578.     ;; bind mouse bindings so we can manipulate the items on each line
  579.     (define-key speedbar-key-map [mouse-2] 'speedbar-click)
  580.     ;; This is the power click for poping up new frames
  581.     (define-key speedbar-key-map [S-mouse-2] 'speedbar-power-click)
  582.     ;; This adds a small unecessary visual effect
  583.     ;;(define-key speedbar-key-map [down-mouse-2] 'speedbar-quick-mouse)
  584.     (define-key speedbar-key-map [M-mouse-2] 'speedbar-mouse-item-info)
  585.  
  586.     ;; disable all menus - we don't have a lot of space to play with
  587.     ;; in such a skinny frame.  This will cleverly find and nuke some
  588.     ;; user-defined menus as well if they are there.  Too bad it
  589.     ;; rely's on the structure of a keymap to work.
  590.     (let ((k (lookup-key global-map [menu-bar])))
  591.       (while k
  592.     (if (and (listp (car k)) (listp (cdr (car k))))
  593.         (define-key speedbar-key-map (vector 'menu-bar (car (car k)))
  594.           'undefined))
  595.     (setq k (cdr k))))
  596.  
  597.     ;; This lets the user scroll as if we had a scrollbar... well maybe not
  598.     (define-key speedbar-key-map [mode-line mouse-2] 'speedbar-mouse-hscroll)
  599.     ))
  600.  
  601. (defvar speedbar-easymenu-definition-base
  602.   '("Speedbar"
  603.     ["Update" speedbar-refresh t]
  604.     ["Auto Update" speedbar-toggle-updates
  605.      :style toggle :selected speedbar-update-flag]
  606.     )
  607.   "Base part of the speedbar menu.")
  608.  
  609. (defvar speedbar-easymenu-definition-special
  610.   '(["Edit Item On Line" speedbar-edit-line t]
  611.     ["Show All Files" speedbar-toggle-show-all-files
  612.      :style toggle :selected speedbar-show-unknown-files]
  613.     ["Expand Item" speedbar-expand-line
  614.      (save-excursion (beginning-of-line)
  615.              (looking-at "[0-9]+: *.\\+. "))]
  616.     ["Contract Item" speedbar-contract-line
  617.      (save-excursion (beginning-of-line)
  618.              (looking-at "[0-9]+: *.-. "))]
  619.     "----"
  620.     ["Item Information" speedbar-item-info t]
  621.     ["Load Lisp File" speedbar-item-load
  622.      (save-excursion
  623.        (beginning-of-line)
  624.        (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\*\\)?$"))]
  625.     ["Byte Compile File" speedbar-item-byte-compile
  626.      (save-excursion
  627.        (beginning-of-line)
  628.        (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\*\\)?$"))]
  629.     ["Copy Item" speedbar-item-copy
  630.      (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))]
  631.     ["Rename Item" speedbar-item-rename
  632.      (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
  633.     ["Delete Item" speedbar-item-delete
  634.      (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))])
  635.   "Additional menu items while in file-mode.")
  636.  
  637. (defvar speedbar-easymenu-definition-trailer
  638.   '("----"
  639.     ["Close" speedbar-close-frame t])
  640.   "Menu items appearing at the end of the speedbar menu.")
  641.  
  642. (defvar speedbar-buffer nil
  643.   "The buffer displaying the speedbar.")
  644. (defvar speedbar-frame nil
  645.   "The frame displaying speedbar.")
  646. (defvar speedbar-cached-frame nil
  647.   "The frame that was last created, then removed from the display.")
  648. (defvar speedbar-full-text-cache nil
  649.   "The last open directory is saved in it's entirety for ultra-fast switching.")
  650. (defvar speedbar-timer nil
  651.   "The speedbar timer used for updating the buffer.")
  652. (defvar speedbar-attached-frame nil
  653.   "The frame which started speedbar mode.
  654. This is the frame from which all data displayed in the speedbar is
  655. gathered, and in which files and such are displayed.")
  656.  
  657. (defvar speedbar-last-selected-file nil
  658.   "The last file which was selected in speedbar buffer.")
  659.  
  660. (defvar speedbar-shown-directories nil
  661.   "Maintain list of directories simultaneously open in the current speedbar.")
  662.  
  663. (defvar speedbar-directory-contents-alist nil
  664.   "An association list of directories and their contents.
  665. Each sublist was returned by `speedbar-file-lists'.  This list is
  666. maintained to speed up the refresh rate when switching between
  667. directories.")
  668.  
  669. (defvar speedbar-power-click nil
  670.   "Never set this by hand.  Value is t when S-mouse activity occurs.")
  671.  
  672.  
  673. ;;; Mode definitions/ user commands
  674. ;;
  675. ;;;###autoload
  676. (defalias 'speedbar 'speedbar-frame-mode)
  677. ;;;###autoload
  678. (defun speedbar-frame-mode (&optional arg)
  679.   "Enable or disable speedbar.  Positive ARG means turn on, negative turn off.
  680. nil means toggle.  Once the speedbar frame is activated, a buffer in
  681. `speedbar-mode' will be displayed.  Currently, only one speedbar is
  682. supported at a time."
  683.   (interactive "P")
  684.   (if (not window-system)
  685.       (error "Speedbar is not useful outside of a windowing environment"))
  686.   ;; toggle frame on and off.
  687.   (if (not arg) (if speedbar-frame (setq arg -1) (setq arg 1)))
  688.   ;; turn the frame off on neg number
  689.   (if (and (numberp arg) (< arg 0))
  690.       (progn
  691.     (run-hooks 'speedbar-before-delete-hook)
  692.     (if (and speedbar-frame (frame-live-p speedbar-frame))
  693.         (if speedbar-xemacsp
  694.         (delete-frame speedbar-frame)
  695.           (setq speedbar-cached-frame speedbar-frame)
  696.           (modify-frame-parameters speedbar-frame '((visibility . nil)))))
  697.     (setq speedbar-frame nil)
  698.     (speedbar-set-timer nil)
  699.     ;; Used to delete the buffer.  This has the annoying affect of
  700.     ;; preventing whatever took it's place from ever appearing
  701.     ;; as the default after a C-x b was typed
  702.     ;;(if (bufferp speedbar-buffer)
  703.     ;;    (kill-buffer speedbar-buffer))
  704.     )
  705.     ;; Set this as our currently attached frame
  706.     (setq speedbar-attached-frame (selected-frame))
  707.     ;; Get the frame to work in
  708.     (if (frame-live-p speedbar-cached-frame)
  709.     (progn
  710.       (setq speedbar-frame speedbar-cached-frame)
  711.       (modify-frame-parameters speedbar-frame '((visibility . t)))
  712.       ;; Get the buffer to play with
  713.       (speedbar-mode)
  714.       (select-frame speedbar-frame)
  715.       (if (not (eq (current-buffer) speedbar-buffer))
  716.           (switch-to-buffer speedbar-buffer))
  717.       (set-window-dedicated-p (selected-window) t)
  718.       (raise-frame speedbar-frame)
  719.       (speedbar-set-timer speedbar-update-speed)
  720.       )
  721.       (if (frame-live-p speedbar-frame)
  722.       (raise-frame speedbar-frame)
  723.     (let ((params (cons (cons 'height (frame-height))
  724.                 speedbar-frame-parameters)))
  725.       (setq speedbar-frame
  726.         (if (or speedbar-xemacsp
  727.             (< emacs-major-version 20)) ;a bug is fixed in v20 & later
  728.             (make-frame params)
  729.           (let ((x-pointer-shape x-pointer-top-left-arrow)
  730.             (x-sensitive-text-pointer-shape x-pointer-hand2))
  731.             (make-frame params)))))
  732.     ;; reset the selection variable
  733.     (setq speedbar-last-selected-file nil)
  734.     ;; Put the buffer into the frame
  735.     (save-window-excursion
  736.       ;; Get the buffer to play with
  737.       (speedbar-mode)
  738.       (select-frame speedbar-frame)
  739.       (switch-to-buffer speedbar-buffer)
  740.       (set-window-dedicated-p (selected-window) t)
  741.       ;; Turn off toolbar and menubar under XEmacs
  742.       (if speedbar-xemacsp
  743.           (progn
  744.         (set-specifier default-toolbar-visible-p
  745.                    (cons (selected-frame) nil))
  746.         ;; These lines make the menu-bar go away nicely, but
  747.         ;; they also cause xemacs much heartache.
  748.         ;;(set-specifier menubar-visible-p (cons (selected-frame) nil))
  749.         ;;(make-local-variable 'current-menubar)
  750.         ;;(setq current-menubar speedbar-menu)
  751.         ;;(add-submenu nil speedbar-menu nil)
  752.         )))
  753.     (speedbar-set-timer speedbar-update-speed)
  754.     ))))
  755.  
  756. (defun speedbar-close-frame ()
  757.   "Turn off a currently active speedbar."
  758.   (interactive)
  759.   (speedbar-frame-mode -1)
  760.   (select-frame speedbar-attached-frame)
  761.   (other-frame 0))
  762.  
  763. (defun speedbar-frame-width ()
  764.   "Return the width of the speedbar frame in characters.
  765. nil if it doesn't exist."
  766.   (and speedbar-frame
  767.        (frame-live-p speedbar-frame)
  768.        (cdr (assoc 'width (frame-parameters speedbar-frame)))))
  769.  
  770. (defun speedbar-mode ()
  771.   "Major mode for managing a display of directories and tags.
  772. \\<speedbar-key-map>
  773. The first line represents the default path of the speedbar frame.
  774. Each directory segment is a button which jumps speedbar's default
  775. directory to that path.  Buttons are activated by clicking `\\[speedbar-click]'.
  776. In some situations using `\\[speedbar-power-click]' is a `power click' which will
  777. rescan cached items, or pop up new frames.
  778.  
  779. Each line starting with <+> represents a directory.  Click on the <+>
  780. to insert the directory listing into the current tree.  Click on the
  781. <-> to retract that list.  Click on the directory name to go to that
  782. directory as the default.
  783.  
  784. Each line starting with [+] is a file.  If the variable
  785. `speedbar-show-unknown-files' is t, the lines starting with [?] are
  786. files which don't have imenu support, but are not expressly ignored.
  787. Files are completely ignored if they match `speedbar-file-unshown-regexp'
  788. which is generated from `completion-ignored-extensions'.
  789.  
  790. Files with a `*' character after their name are files checked out of a
  791. version control system.  (currently only RCS is supported.)  New
  792. version control systems can be added by examining the documentation
  793. for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'
  794.  
  795. Click on the [+] to display a list of tags from that file.  Click on
  796. the [-] to retract the list.  Click on the file name to edit the file
  797. in the attached frame.
  798.  
  799. If you open tags, you might find a node starting with {+}, which is a
  800. category of tags.  Click the {+} to expand the category.  Jump-able
  801. tags start with >.  Click the name of the tag to go to that position
  802. in the selected file.
  803.  
  804. \\{speedbar-key-map}"
  805.   ;; NOT interactive
  806.   (save-excursion
  807.     (setq speedbar-buffer (set-buffer (get-buffer-create " SPEEDBAR")))
  808.     (kill-all-local-variables)
  809.     (setq major-mode 'speedbar-mode)
  810.     (setq mode-name "Speedbar")
  811.     (use-local-map speedbar-key-map)
  812.     (set-syntax-table speedbar-syntax-table)
  813.     (setq font-lock-keywords nil) ;; no font-locking please
  814.     (setq truncate-lines t)
  815.     (make-local-variable 'frame-title-format)
  816.     (setq frame-title-format "Speedbar")
  817.     ;; Set this up special just for the speedbar buffer
  818.     (if (null default-minibuffer-frame)
  819.     (progn
  820.       (make-local-variable 'default-minibuffer-frame)
  821.       (setq default-minibuffer-frame speedbar-attached-frame)))
  822.     (make-local-variable 'temp-buffer-show-function)
  823.     (setq temp-buffer-show-function 'speedbar-temp-buffer-show-function)
  824.     (setq kill-buffer-hook '(lambda () (let ((skilling (boundp 'skilling)))
  825.                      (if skilling
  826.                          nil
  827.                        (if (eq (current-buffer)
  828.                            speedbar-buffer)
  829.                            (speedbar-frame-mode -1))))))
  830.     (speedbar-set-mode-line-format)
  831.     (if (not speedbar-xemacsp)
  832.     (setq auto-show-mode nil))    ;no auto-show for Emacs
  833.     (run-hooks 'speedbar-mode-hook))
  834.   (speedbar-update-contents)
  835.   speedbar-buffer)
  836.  
  837. (defun speedbar-set-mode-line-format ()
  838.   "Set the format of the mode line based on the current speedbar environment.
  839. This gives visual indications of what is up.  It EXPECTS the speedbar
  840. frame and window to be the currently active frame and window."
  841.   (if (frame-live-p speedbar-frame)
  842.       (save-excursion
  843.     (set-buffer speedbar-buffer)
  844.     (let* ((w (or (speedbar-frame-width) 20))
  845.            (p1 "<<")
  846.            (p5 ">>")
  847.            (p3 (if speedbar-update-flag "SPEEDBAR" "SLOWBAR"))
  848.            (blank (- w (length p1) (length p3) (length p5)
  849.              (if line-number-mode 4 0)))
  850.            (p2 (if (> blank 0)
  851.                (make-string (/ blank 2) ? )
  852.              ""))
  853.            (p4 (if (> blank 0)
  854.                (make-string (+ (/ blank 2) (% blank 2)) ? )
  855.              ""))
  856.            (tf
  857.         (if line-number-mode
  858.             (list (concat p1 p2 p3) '(line-number-mode " %3l")
  859.               (concat p4 p5))
  860.           (list (concat p1 p2 p3 p4 p5)))))
  861.       (if (not (equal mode-line-format tf))
  862.           (progn
  863.         (setq mode-line-format tf)
  864.         (force-mode-line-update)))))))
  865.  
  866. (defun speedbar-temp-buffer-show-function (buffer)
  867.   "Placed in the variable `temp-buffer-show-function' in `speedbar-mode'.
  868. If a user requests help using \\[help-command] <Key> the temp BUFFER will be
  869. redirected into a window on the attached frame."
  870.   (if speedbar-attached-frame (select-frame speedbar-attached-frame))
  871.   (pop-to-buffer buffer nil)
  872.   (other-window -1)
  873.   (run-hooks 'temp-buffer-show-hook))
  874.  
  875. (defun speedbar-reconfigure-menubar ()
  876.   "Reconfigure the menu-bar in a speedbar frame.
  877. Different menu items are displayed depending on the current display mode
  878. and the existence of packages."
  879.   (let ((km (make-sparse-keymap))
  880.     (cf (selected-frame))
  881.     (md (append speedbar-easymenu-definition-base
  882.             (if speedbar-shown-directories
  883.             ;; file display mode version
  884.             speedbar-easymenu-definition-special
  885.               (save-excursion
  886.             (select-frame speedbar-attached-frame)
  887.             (if (local-variable-p
  888.                  'speedbar-easymenu-definition-special
  889.                  (current-buffer))
  890.                 ;; If bound locally, we can use it
  891.                 speedbar-easymenu-definition-special)))
  892.             ;; The trailer
  893.             speedbar-easymenu-definition-trailer)))
  894.     (easy-menu-define speedbar-menu-map speedbar-key-map "Speedbar menu" md)
  895.     ;; (if speedbar-xemacsp (set-buffer-menubar (list km)))
  896. ))
  897.  
  898.  
  899. ;;; User Input stuff
  900. ;;
  901. (defun speedbar-mouse-hscroll (e)
  902.   "Read a mouse event E from the mode line, and horizontally scroll.
  903. If the mouse is being clicked on the far left, or far right of the
  904. mode-line.  This is only useful for non-XEmacs"
  905.   (interactive "e")
  906.   (let* ((xp (car (nth 2 (car (cdr e)))))
  907.      (cpw (/ (frame-pixel-width)
  908.          (frame-width)))
  909.      (oc (1+ (/ xp cpw)))
  910.      )
  911.     (cond ((< oc 3)
  912.        (scroll-left 2))
  913.       ((> oc (- (window-width) 3))
  914.        (scroll-right 2))
  915.       (t (message "Click on the edge of the modeline to scroll left/right")))
  916.     ;;(message "X: Pixel %d Char Pixels %d On char %d" xp cpw oc)
  917.     ))
  918.  
  919. ;;;###autoload
  920. (defun speedbar-get-focus ()
  921.   "Change frame focus to or from the speedbar frame.
  922. If the selected frame is not speedbar, then speedbar frame is
  923. selected.  If the speedbar frame is active, then select the attached frame."
  924.   (interactive)
  925.   (if (eq (selected-frame) speedbar-frame)
  926.       (if (frame-live-p speedbar-attached-frame)
  927.       (select-frame speedbar-attached-frame))
  928.     ;; make sure we have a frame
  929.     (if (not (frame-live-p speedbar-frame)) (speedbar-frame-mode 1))
  930.     ;; go there
  931.     (select-frame speedbar-frame))
  932.   (other-frame 0))
  933.  
  934. (defun speedbar-next (arg)
  935.   "Move to the next ARGth line in a speedbar buffer."
  936.   (interactive "p")
  937.   (forward-line (or arg 1))
  938.   (speedbar-item-info)
  939.   (speedbar-position-cursor-on-line))
  940.  
  941. (defun speedbar-prev (arg)
  942.   "Move to the previous ARGth line in a speedbar buffer."
  943.   (interactive "p")
  944.   (speedbar-next (if arg (- arg) -1)))
  945.  
  946. (defun speedbar-scroll-up (&optional arg)
  947.   "Page down one screen-full of the speedbar, or ARG lines."
  948.   (interactive "P")
  949.   (scroll-up arg)
  950.   (speedbar-position-cursor-on-line))
  951.  
  952. (defun speedbar-scroll-down (&optional arg)
  953.   "Page up one screen-full of the speedbar, or ARG lines."
  954.   (interactive "P")
  955.   (scroll-down arg)
  956.   (speedbar-position-cursor-on-line))
  957.  
  958. (defun speedbar-up-directory ()
  959.   "Keyboard accelerator for moving the default directory up one.
  960. Assumes that the current buffer is the speedbar buffer"
  961.   (interactive)
  962.   (setq default-directory (expand-file-name (concat default-directory "../")))
  963.   (speedbar-update-contents))
  964.  
  965. ;;; Speedbar file activity
  966. ;;
  967. (defun speedbar-refresh ()
  968.   "Refresh the current speedbar display, disposing of any cached data."
  969.   (interactive)
  970.   (let ((dl speedbar-shown-directories))
  971.     (while dl
  972.       (adelete 'speedbar-directory-contents-alist (car dl))
  973.       (setq dl (cdr dl))))
  974.   (if (<= 1 speedbar-verbosity-level) (message "Refreshing speedbar..."))
  975.   (speedbar-update-contents)
  976.   (speedbar-stealthy-updates)
  977.   ;; Reset the timer in case it got really hosed for some reason...
  978.   (speedbar-set-timer speedbar-update-speed)
  979.   (if (<= 1 speedbar-verbosity-level) (message "Refreshing speedbar...done")))
  980.  
  981. (defun speedbar-item-load ()
  982.   "Byte compile the item under the cursor or mouse if it is a lisp file."
  983.   (interactive)
  984.   (let ((f (speedbar-line-file)))
  985.     (if (and (file-exists-p f) (string-match "\\.el$" f))
  986.     (if (and (file-exists-p (concat f "c"))
  987.          (y-or-n-p (format "Load %sc? " f)))
  988.         ;; If the compiled version exists, load that instead...
  989.         (load-file (concat f "c"))
  990.       (load-file f))
  991.       (error "Not a loadable file..."))))
  992.  
  993. (defun speedbar-item-byte-compile ()
  994.   "Byte compile the item under the cursor or mouse if it is a lisp file."
  995.   (interactive)
  996.   (let ((f (speedbar-line-file))
  997.     (sf (selected-frame)))
  998.     (if (and (file-exists-p f) (string-match "\\.el$" f))
  999.     (progn
  1000.       (select-frame speedbar-attached-frame)
  1001.       (byte-compile-file f nil)
  1002.       (select-frame sf)))
  1003.     ))
  1004.  
  1005. (defun speedbar-mouse-item-info (event)
  1006.   "Provide information about what the user clicked on.
  1007. This should be bound to a mouse EVENT."
  1008.   (interactive "e")
  1009.   (mouse-set-point event)
  1010.   (speedbar-item-info))
  1011.  
  1012. (defun speedbar-item-info ()
  1013.   "Display info in the mini-buffer about the button the mouse is over."
  1014.   (interactive)
  1015.   (if (not speedbar-shown-directories)
  1016.       nil
  1017.     (let* ((item (speedbar-line-file))
  1018.        (attr (if item (file-attributes item) nil)))
  1019.       (if item (message "%s %d %s" (nth 8 attr) (nth 7 attr) item)
  1020.     (save-excursion
  1021.       (beginning-of-line)
  1022.       (looking-at "\\([0-9]+\\):")
  1023.       (setq item (speedbar-line-path (string-to-int (match-string 1))))
  1024.       (if (re-search-forward "> \\([^ ]+\\)$"
  1025.                  (save-excursion(end-of-line)(point)) t)
  1026.           (progn
  1027.         (setq attr (get-text-property (match-beginning 1)
  1028.                           'speedbar-token))
  1029.         (message "Tag %s in %s at position %s"
  1030.              (match-string 1) item (if attr attr 0)))
  1031.         (message "No special info for this line.")))
  1032.     ))))
  1033.  
  1034. (defun speedbar-item-copy ()
  1035.   "Copy the item under the cursor.
  1036. Files can be copied to new names or places."
  1037.   (interactive)
  1038.   (let ((f (speedbar-line-file)))
  1039.     (if (not f)    (error "Not a file."))
  1040.     (if (file-directory-p f)
  1041.     (error "Cannot copy directory.")
  1042.       (let* ((rt (read-file-name (format "Copy %s to: "
  1043.                      (file-name-nondirectory f))
  1044.                  (file-name-directory f)))
  1045.          (refresh (member (expand-file-name (file-name-directory rt))
  1046.                   speedbar-shown-directories)))
  1047.     ;; Create the right file name part
  1048.     (if (file-directory-p rt)
  1049.         (setq rt
  1050.           (concat (expand-file-name rt)
  1051.               (if (string-match "/$" rt) "" "/")
  1052.               (file-name-nondirectory f))))
  1053.     (if (or (not (file-exists-p rt))
  1054.         (y-or-n-p (format "Overwrite %s with %s? " rt f)))
  1055.         (progn
  1056.           (copy-file f rt t t)
  1057.           ;; refresh display if the new place is currently displayed.
  1058.           (if refresh
  1059.           (progn
  1060.             (speedbar-refresh)
  1061.             (if (not (speedbar-goto-this-file rt))
  1062.             (speedbar-goto-this-file f))))
  1063.           ))))))
  1064.  
  1065. (defun speedbar-item-rename ()
  1066.   "Rename the item under the cursor or mouse.
  1067. Files can be renamed to new names or moved to new directories."
  1068.   (interactive)
  1069.   (let ((f (speedbar-line-file)))
  1070.     (if f
  1071.     (let* ((rt (read-file-name (format "Rename %s to: "
  1072.                        (file-name-nondirectory f))
  1073.                    (file-name-directory f)))
  1074.            (refresh (member (expand-file-name (file-name-directory rt))
  1075.                 speedbar-shown-directories)))
  1076.       ;; Create the right file name part
  1077.       (if (file-directory-p rt)
  1078.           (setq rt
  1079.             (concat (expand-file-name rt)
  1080.                 (if (string-match "/$" rt) "" "/")
  1081.                 (file-name-nondirectory f))))
  1082.       (if (or (not (file-exists-p rt))
  1083.           (y-or-n-p (format "Overwrite %s with %s? " rt f)))
  1084.           (progn
  1085.         (rename-file f rt t)
  1086.         ;; refresh display if the new place is currently displayed.
  1087.         (if refresh
  1088.             (progn
  1089.               (speedbar-refresh)
  1090.               (speedbar-goto-this-file rt)
  1091.               )))))
  1092.       (error "Not a file."))))
  1093.  
  1094. (defun speedbar-item-delete ()
  1095.   "Delete the item under the cursor.  Files are removed from disk."
  1096.   (interactive)
  1097.   (let ((f (speedbar-line-file)))
  1098.     (if (not f) (error "Not a file."))
  1099.     (if (y-or-n-p (format "Delete %s? " f))
  1100.     (progn
  1101.       (if (file-directory-p f)
  1102.           (delete-directory f)
  1103.         (delete-file f))
  1104.       (message "Okie dokie..")
  1105.       (let ((p (point)))
  1106.         (speedbar-refresh)
  1107.         (goto-char p))
  1108.       ))
  1109.     ))
  1110.  
  1111. (defun speedbar-enable-update ()
  1112.   "Enable automatic updating in speedbar via timers."
  1113.   (interactive)
  1114.   (setq speedbar-update-flag t)
  1115.   (speedbar-set-mode-line-format)
  1116.   (speedbar-set-timer speedbar-update-speed))
  1117.  
  1118. (defun speedbar-disable-update ()
  1119.   "Disable automatic updating and stop consuming resources."
  1120.   (interactive)
  1121.   (setq speedbar-update-flag nil)
  1122.   (speedbar-set-mode-line-format)
  1123.   (speedbar-set-timer nil))
  1124.  
  1125. (defun speedbar-toggle-updates ()
  1126.   "Toggle automatic update for the speedbar frame."
  1127.   (interactive)
  1128.   (if speedbar-update-flag
  1129.       (speedbar-disable-update)
  1130.     (speedbar-enable-update)))
  1131.  
  1132. (defun speedbar-toggle-show-all-files ()
  1133.   "Toggle display of files speedbar can not tag."
  1134.   (interactive)
  1135.   (setq speedbar-show-unknown-files (not speedbar-show-unknown-files))
  1136.   (speedbar-refresh))
  1137.  
  1138. ;;; Utility functions
  1139. ;;
  1140. (defun speedbar-set-timer (timeout)
  1141.   "Unset an old timer (if there is one) and activate a new timer with TIMEOUT.
  1142. TIMEOUT is the number of seconds until the speedbar timer is called
  1143. again."
  1144.   (cond
  1145.    ;; XEmacs
  1146.    (speedbar-xemacsp
  1147.     (if speedbar-timer
  1148.     (progn (delete-itimer speedbar-timer)
  1149.            (setq speedbar-timer nil)))
  1150.     (if timeout
  1151.     (setq speedbar-timer (start-itimer "speedbar"
  1152.                        'speedbar-timer-fn
  1153.                        timeout
  1154.                        nil))))
  1155.    ;; Post 19.31 Emacs
  1156.    ((fboundp 'run-with-idle-timer)
  1157.     (if speedbar-timer
  1158.     (progn (cancel-timer speedbar-timer)
  1159.            (setq speedbar-timer nil)))
  1160.     (if timeout
  1161.     (setq speedbar-timer
  1162.           (run-with-idle-timer timeout nil 'speedbar-timer-fn))))
  1163.    ;; Older or other Emacsen with no timers.  Set up so that it's
  1164.    ;; obvious this emacs can't handle the updates
  1165.    (t
  1166.     (setq speedbar-update-flag nil)))
  1167.    ;; change this if it changed for some reason
  1168.   (speedbar-set-mode-line-format))
  1169.  
  1170. (defmacro speedbar-with-writable (&rest forms)
  1171.   "Allow the buffer to be writable and evaluate FORMS.
  1172. Turn read only back on when done."
  1173.   (list 'let '((speedbar-with-writable-buff (current-buffer)))
  1174.     '(toggle-read-only -1)
  1175.     (cons 'progn forms)
  1176.     '(save-excursion (set-buffer speedbar-with-writable-buff)
  1177.              (toggle-read-only 1))))
  1178. (put 'speedbar-with-writable 'lisp-indent-function 0)
  1179.  
  1180. (defun speedbar-select-window (buffer)
  1181.   "Select a window in which BUFFER is show.
  1182. If it is not shown, force it to appear in the default window."
  1183.   (let ((win (get-buffer-window buffer speedbar-attached-frame)))
  1184.     (if win
  1185.     (select-window win)
  1186.       (show-buffer (selected-window) buffer))))
  1187.  
  1188. (defmacro speedbar-with-attached-buffer (&rest forms)
  1189.   "Execute FORMS in the attached frame's special buffer.
  1190. Optionally select that frame if necessary."
  1191.   ;; Reset the timer with a new timeout when cliking a file
  1192.   ;; in case the user was navigating directories, we can cancel
  1193.   ;; that other timer.
  1194.   (list
  1195.    'progn
  1196.    '(speedbar-set-timer speedbar-update-speed)
  1197.    (list
  1198.     'let '((cf (selected-frame)))
  1199.     '(select-frame speedbar-attached-frame)
  1200.     '(speedbar-select-window speedbar-desired-buffer)
  1201.     (cons 'progn forms)
  1202.     '(select-frame cf)
  1203.     '(speedbar-maybee-jump-to-attached-frame)
  1204.     )))
  1205.  
  1206. (defun speedbar-insert-button (text face mouse function
  1207.                     &optional token prevline)
  1208.   "Insert TEXT as the next logical speedbar button.
  1209. FACE is the face to put on the button, MOUSE is the highlight face to use.
  1210. When the user clicks on TEXT, FUNCTION is called with the TOKEN parameter.
  1211. This function assumes that the current buffer is the speedbar buffer.
  1212. If PREVLINE, then put this button on the previous line.
  1213.  
  1214. This is a convenience function for special mode that create their own
  1215. specialized speedbar displays."
  1216.   (goto-char (point-max))
  1217.   (if (/= (current-column) 0) (insert "\n"))
  1218.   (if prevline (progn (delete-char -1) (insert " "))) ;back up if desired...
  1219.   (let ((start (point)))
  1220.     (insert text)
  1221.     (speedbar-make-button start (point) face mouse function token))
  1222.   (let ((start (point)))
  1223.     (insert "\n")
  1224.     (put-text-property start (point) 'face nil)
  1225.     (put-text-property start (point) 'mouse-face nil)))
  1226.  
  1227. (defun speedbar-make-button (start end face mouse function &optional token)
  1228.   "Create a button from START to END, with FACE as the display face.
  1229. MOUSE is the mouse face.  When this button is clicked on FUNCTION
  1230. will be run with the TOKEN parameter (any lisp object)"
  1231.   (put-text-property start end 'face face)
  1232.   (put-text-property start end 'mouse-face mouse)
  1233.   (put-text-property start end 'invisible nil)
  1234.   (if function (put-text-property start end 'speedbar-function function))
  1235.   (if token (put-text-property start end 'speedbar-token token))
  1236.   )
  1237.  
  1238. ;;; File button management
  1239. ;;
  1240. (defun speedbar-file-lists (directory)
  1241.   "Create file lists for DIRECTORY.
  1242. The car is the list of directories, the cdr is list of files not
  1243. matching ignored headers.  Cache any directory files found in
  1244. `speedbar-directory-contents-alist' and use that cache before scanning
  1245. the file-system"
  1246.   (setq directory (expand-file-name directory))
  1247.   ;; If in powerclick mode, then the directory we are getting
  1248.   ;; should be rescanned.
  1249.   (if speedbar-power-click
  1250.       (adelete 'speedbar-directory-contents-alist directory))
  1251.   ;; find the directory, either in the cache, or build it.
  1252.   (or (cdr-safe (assoc directory speedbar-directory-contents-alist))
  1253.       (let ((default-directory directory)
  1254.         (dir (directory-files directory nil))
  1255.         (dirs nil)
  1256.         (files nil))
  1257.     (while dir
  1258.       (if (not (string-match speedbar-file-unshown-regexp (car dir)))
  1259.           (if (file-directory-p (car dir))
  1260.           (setq dirs (cons (car dir) dirs))
  1261.         (setq files (cons (car dir) files))))
  1262.       (setq dir (cdr dir)))
  1263.     (let ((nl (cons (nreverse dirs) (list (nreverse files)))))
  1264.       (aput 'speedbar-directory-contents-alist directory nl)
  1265.       nl))
  1266.       ))
  1267.  
  1268. (defun speedbar-directory-buttons (directory index)
  1269.   "Insert a single button group at point for DIRECTORY.
  1270. Each directory path part is a different button.  If part of the path
  1271. matches the user directory ~, then it is replaced with a ~.
  1272. INDEX is not used, but is required by the caller."
  1273.   (let* ((tilde (expand-file-name "~"))
  1274.      (dd (expand-file-name directory))
  1275.      (junk (string-match (regexp-quote tilde) dd))
  1276.      (displayme (if junk
  1277.             (concat "~" (substring dd (match-end 0)))
  1278.               dd))
  1279.      (p (point)))
  1280.     (if (string-match "^~/?$" displayme) (setq displayme (concat tilde "/")))
  1281.     (insert displayme)
  1282.     (save-excursion
  1283.       (goto-char p)
  1284.       (while (re-search-forward "\\([^/]+\\)/" nil t)
  1285.     (speedbar-make-button (match-beginning 1) (match-end 1)
  1286.                   'speedbar-directory-face
  1287.                   'speedbar-highlight-face
  1288.                   'speedbar-directory-buttons-follow
  1289.                   (if (= (match-beginning 1) p)
  1290.                   (expand-file-name "~/")  ;the tilde
  1291.                 (buffer-substring-no-properties
  1292.                  p (match-end 0)))))
  1293.       ;; Nuke the beginning of the directory if it's too long...
  1294.       (cond ((eq speedbar-directory-button-trim-method 'span)
  1295.          (beginning-of-line)
  1296.          (let ((ww (or (speedbar-frame-width) 20)))
  1297.            (move-to-column ww nil)
  1298.            (while (>= (current-column) ww)
  1299.          (re-search-backward "/" nil t)
  1300.          (if (<= (current-column) 2)
  1301.              (progn
  1302.                (re-search-forward "/" nil t)
  1303.                (if (< (current-column) 4)
  1304.                (re-search-forward "/" nil t))
  1305.                (forward-char -1)))
  1306.          (if (looking-at "/?$")
  1307.              (beginning-of-line)
  1308.            (insert "/...\n ")
  1309.            (move-to-column ww nil)))))
  1310.         ((eq speedbar-directory-button-trim-method 'trim)
  1311.          (end-of-line)
  1312.          (let ((ww (or (speedbar-frame-width) 20))
  1313.            (tl (current-column)))
  1314.            (if (< ww tl)
  1315.            (progn
  1316.              (move-to-column (- tl ww))
  1317.              (if (re-search-backward "/" nil t)
  1318.              (progn
  1319.                (delete-region (point-min) (point))
  1320.                (insert "$")
  1321.                )))))))
  1322.       )
  1323.     (if (string-match "^/[^/]+/$" displayme)
  1324.     (progn
  1325.       (insert "  ")
  1326.       (let ((p (point)))
  1327.         (insert "<root>")
  1328.         (speedbar-make-button p (point)
  1329.                   'speedbar-directory-face
  1330.                   'speedbar-highlight-face
  1331.                   'speedbar-directory-buttons-follow
  1332.                   "/"))))
  1333.     (end-of-line)
  1334.     (insert-char ?\n 1 nil)))
  1335.  
  1336. (defun speedbar-make-tag-line (exp-button-type
  1337.                    exp-button-char exp-button-function
  1338.                    exp-button-data
  1339.                    tag-button tag-button-function tag-button-data
  1340.                    tag-button-face depth)
  1341.   "Create a tag line with EXP-BUTTON-TYPE for the small expansion button.
  1342. This is the button that expands or contracts a node (if applicable),
  1343. and EXP-BUTTON-CHAR the character in it (+, -, ?, etc).  EXP-BUTTON-FUNCTION
  1344. is the function to call if it's clicked on.  Button types are
  1345. 'bracket, 'angle, 'curly, or nil.  EXP-BUTTON-DATA is extra data
  1346. attached to the text forming the expansion button.
  1347.  
  1348. Next, TAG-BUTTON is the text of the tag.  TAG-BUTTON-FUNCTION is the
  1349. function to call if clicked on, and TAG-BUTTON-DATA is the data to
  1350. attach to the text field (such a tag positioning, etc).
  1351. TAG-BUTTON-FACE is a face used for this type of tag.
  1352.  
  1353. Lastly, DEPTH shows the depth of expansion.
  1354.  
  1355. This function assumes that the cursor is in the speedbar window at the
  1356. position to insert a new item, and that the new item will end with a CR"
  1357.   (let ((start (point))
  1358.     (end (progn
  1359.            (insert (int-to-string depth) ":")
  1360.            (point))))
  1361.     (put-text-property start end 'invisible t)
  1362.     )
  1363.   (insert-char ?  depth nil)
  1364.   (put-text-property (- (point) depth) (point) 'invisible nil)
  1365.   (let* ((exp-button (cond ((eq exp-button-type 'bracket) "[%c]")
  1366.                ((eq exp-button-type 'angle) "<%c>")
  1367.                ((eq exp-button-type 'curly) "{%c}")
  1368.                (t ">")))
  1369.      (buttxt (format exp-button exp-button-char))
  1370.      (start (point))
  1371.      (end (progn (insert buttxt) (point)))
  1372.      (bf (if exp-button-type 'speedbar-button-face nil))
  1373.      (mf (if exp-button-function 'speedbar-highlight-face nil))
  1374.      )
  1375.     (speedbar-make-button start end bf mf exp-button-function exp-button-data)
  1376.     )
  1377.   (insert-char ?  1 nil)
  1378.   (put-text-property (1- (point)) (point) 'invisible nil)
  1379.   (let ((start (point))
  1380.     (end (progn (insert tag-button) (point))))
  1381.     (insert-char ?\n 1 nil)
  1382.     (put-text-property (1- (point)) (point) 'invisible nil)
  1383.     (speedbar-make-button start end tag-button-face
  1384.               (if tag-button-function 'speedbar-highlight-face nil)
  1385.               tag-button-function tag-button-data))
  1386. )
  1387.  
  1388. (defun speedbar-change-expand-button-char (char)
  1389.   "Change the expansion button character to CHAR for the current line."
  1390.   (save-excursion
  1391.     (beginning-of-line)
  1392.     (if (re-search-forward ":\\s-*.\\([-+?]\\)" (save-excursion (end-of-line)
  1393.                                 (point)) t)
  1394.     (speedbar-with-writable
  1395.       (goto-char (match-beginning 1))
  1396.       (delete-char 1)
  1397.       (insert-char char 1 t)))))
  1398.  
  1399.  
  1400. ;;; Build button lists
  1401. ;;
  1402. (defun speedbar-insert-files-at-point (files level)
  1403.   "Insert list of FILES starting at point, and indenting all files to LEVEL.
  1404. Tag expandable items with a +, otherwise a ?.  Don't highlight ? as we
  1405. don't know how to manage them.  The input parameter FILES is a cons
  1406. cell of the form ( 'DIRLIST . 'FILELIST )"
  1407.   ;; Start inserting all the directories
  1408.   (let ((dirs (car files)))
  1409.     (while dirs
  1410.       (speedbar-make-tag-line 'angle ?+ 'speedbar-dired (car dirs)
  1411.                   (car dirs) 'speedbar-dir-follow nil
  1412.                   'speedbar-directory-face level)
  1413.       (setq dirs (cdr dirs))))
  1414.   (let ((lst (car (cdr files))))
  1415.     (while lst
  1416.       (let* ((known (string-match speedbar-file-regexp (car lst)))
  1417.          (expchar (if known ?+ ??))
  1418.          (fn (if known 'speedbar-tag-file nil)))
  1419.     (if (or speedbar-show-unknown-files (/= expchar ??))
  1420.         (speedbar-make-tag-line 'bracket expchar fn (car lst)
  1421.                     (car lst) 'speedbar-find-file nil
  1422.                     'speedbar-file-face level)))
  1423.       (setq lst (cdr lst)))))
  1424.  
  1425. (defun speedbar-default-directory-list (directory index)
  1426.   "Insert files for DIRECTORY with level INDEX at point."
  1427.   (speedbar-insert-files-at-point
  1428.    (speedbar-file-lists directory) index)
  1429.   (speedbar-reset-scanners)
  1430.   (if (= index 0)
  1431.       ;; If the shown files variable has extra directories, then
  1432.       ;; it is our responsibility to redraw them all
  1433.       ;; Luckilly, the nature of inserting items into this list means
  1434.       ;; that by reversing it, we can easilly go in the right order
  1435.       (let ((sf (cdr (reverse speedbar-shown-directories))))
  1436.     (setq speedbar-shown-directories
  1437.           (list (expand-file-name default-directory)))
  1438.     ;; exand them all as we find them
  1439.     (while sf
  1440.       (if (speedbar-goto-this-file (car sf))
  1441.           (progn
  1442.         (beginning-of-line)
  1443.         (if (looking-at "[0-9]+:[ ]*<")
  1444.             (progn
  1445.               (goto-char (match-end 0))
  1446.           (speedbar-do-function-pointer)))
  1447.         (setq sf (cdr sf)))))
  1448.     )))
  1449.  
  1450. (defun speedbar-insert-generic-list (level lst expand-fun find-fun)
  1451.   "At LEVEL, insert a generic multi-level alist LST.
  1452. Associations with lists get {+} tags (to expand into more nodes) and
  1453. those with positions just get a > as the indicator.  {+} buttons will
  1454. have the function EXPAND-FUN and the token is the CDR list.  The token
  1455. name will have the function FIND-FUN and not token."
  1456.   ;; Remove imenu rescan button
  1457.   (if (string= (car (car lst)) "*Rescan*")
  1458.       (setq lst (cdr lst)))
  1459.   ;; insert the parts
  1460.   (while lst
  1461.     (cond ((null (car-safe lst)) nil)    ;this would be a separator
  1462.       ((or (numberp (cdr-safe (car-safe lst)))
  1463.            (markerp (cdr-safe (car-safe lst))))
  1464.        (speedbar-make-tag-line nil nil nil nil ;no expand button data
  1465.                    (car (car lst)) ;button name
  1466.                    find-fun        ;function
  1467.                    (cdr (car lst)) ;token is position
  1468.                    'speedbar-tag-face
  1469.                    (1+ level)))
  1470.       ((listp (cdr-safe (car-safe lst)))
  1471.        (speedbar-make-tag-line 'curly ?+ expand-fun (cdr (car lst))
  1472.                    (car (car lst)) ;button name
  1473.                    nil nil 'speedbar-tag-face
  1474.                    (1+ level)))
  1475.       (t (message "Ooops!")))
  1476.     (setq lst (cdr lst))))
  1477.  
  1478. ;;; Timed functions
  1479. ;;
  1480. (defun speedbar-update-contents ()
  1481.   "Generically update the contents of the speedbar buffer."
  1482.   (interactive)
  1483.   ;; Set the current special buffer
  1484.   (setq speedbar-desired-buffer nil)
  1485.   (if (and speedbar-mode-specific-contents-flag
  1486.        speedbar-special-mode-expansion-list
  1487.        (local-variable-p
  1488.         'speedbar-special-mode-expansion-list
  1489.         (current-buffer)))
  1490.        ;(eq (get major-mode 'mode-class 'special)))
  1491.       (speedbar-update-special-contents)
  1492.     (speedbar-update-directory-contents)))
  1493.  
  1494. (defun speedbar-update-directory-contents ()
  1495.   "Update the contents of the speedbar buffer based on the current directory."
  1496.   (let ((cbd (expand-file-name default-directory))
  1497.     (funclst speedbar-initial-expansion-list)
  1498.     (cache speedbar-full-text-cache)
  1499.     ;; disable stealth during update
  1500.     (speedbar-stealthy-function-list nil)
  1501.     (use-cache nil)
  1502.     ;; Because there is a bug I can't find just yet
  1503.     (inhibit-quit nil))
  1504.     (save-excursion
  1505.       (set-buffer speedbar-buffer)
  1506.       ;; If we are updating contents to a where we are, then this is
  1507.       ;; really a request to update existing contents, so we must be
  1508.       ;; careful with our text cache!
  1509.       (if (member cbd speedbar-shown-directories)
  1510.       (setq cache nil)
  1511.     ;; If this directory is NOT in the current list of available
  1512.     ;; paths, then use the cache, and set the cache to our new
  1513.     ;; value.  Make sure to unhighlight the current file, or if we
  1514.     ;; come back to this directory, it might be a different file
  1515.     ;; and then we get a mess!
  1516.     (if (> (point-max) 1)
  1517.         (progn
  1518.           (speedbar-clear-current-file)
  1519.           (setq speedbar-full-text-cache
  1520.             (cons speedbar-shown-directories (buffer-string)))))
  1521.  
  1522.     ;; Check if our new directory is in the list of directories
  1523.     ;; show in the text-cahce
  1524.     (if (member cbd (car cache))
  1525.         (setq speedbar-shown-directories (car cache)
  1526.           use-cache t)
  1527.       ;; default the shown directories to this list...
  1528.       (setq speedbar-shown-directories (list cbd)))
  1529.     )
  1530.       (setq speedbar-last-selected-file nil)
  1531.       (speedbar-with-writable
  1532.     (setq default-directory cbd)
  1533.     (erase-buffer)
  1534.     (if use-cache
  1535.         (insert (cdr cache))
  1536.       (while funclst
  1537.         (funcall (car funclst) cbd 0)
  1538.         (setq funclst (cdr funclst)))))
  1539.       (goto-char (point-min))))
  1540.   (speedbar-reconfigure-menubar))
  1541.  
  1542. (defun speedbar-update-special-contents ()
  1543.   "Used the mode-specific variable to fill in the speedbar buffer.
  1544. This should only be used by modes classified as special."
  1545.   (let ((funclst speedbar-special-mode-expansion-list)
  1546.     (specialbuff (current-buffer)))
  1547.     (save-excursion
  1548.       (setq speedbar-desired-buffer specialbuff)
  1549.       (set-buffer speedbar-buffer)
  1550.       ;; If we are leaving a directory, cache it.
  1551.       (if (not speedbar-shown-directories)
  1552.       ;; Do nothing
  1553.       nil
  1554.     ;; Clean up directory maintenance stuff
  1555.     (speedbar-clear-current-file)
  1556.     (setq speedbar-full-text-cache
  1557.           (cons speedbar-shown-directories (buffer-string))
  1558.           speedbar-shown-directories nil))
  1559.       ;; Now fill in the buffer with our newly found specialized list.
  1560.       (speedbar-with-writable
  1561.     (while funclst
  1562.       ;; We do not erase the buffer because these functions may
  1563.       ;; decide NOT to update themselves.
  1564.       (funcall (car funclst) specialbuff)
  1565.       (setq funclst (cdr funclst))))
  1566.       (goto-char (point-min))))
  1567.   (speedbar-reconfigure-menubar))
  1568.  
  1569. (defun speedbar-timer-fn ()
  1570.   "Run whenever emacs is idle to update the speedbar item."
  1571.   (if (not (and (frame-live-p speedbar-frame)
  1572.         (frame-live-p speedbar-attached-frame)))
  1573.       (speedbar-set-timer nil)
  1574.     (condition-case nil
  1575.     ;; Save all the match data so that we don't mess up executing fns
  1576.     (save-match-data
  1577.       (if (and (frame-visible-p speedbar-frame) speedbar-update-flag)
  1578.           (let ((af (selected-frame)))
  1579.         (save-window-excursion
  1580.           (select-frame speedbar-attached-frame)
  1581.           ;; make sure we at least choose a window to
  1582.           ;; get a good directory from
  1583.           (if (string-match "\\*Minibuf-[0-9]+\\*" (buffer-name))
  1584.               (other-window 1))
  1585.           ;; Update for special mode all the time!
  1586.           (if (and speedbar-mode-specific-contents-flag
  1587.                speedbar-special-mode-expansion-list
  1588.                (local-variable-p
  1589.                 'speedbar-special-mode-expansion-list
  1590.                 (current-buffer)))
  1591.                     ;(eq (get major-mode 'mode-class 'special)))
  1592.               (speedbar-update-special-contents)
  1593.             ;; Update all the contents if directories change!
  1594.             (if (or (member (expand-file-name default-directory)
  1595.                     speedbar-shown-directories)
  1596.                 (string-match speedbar-ignored-path-regexp
  1597.                       (expand-file-name default-directory))
  1598.                 (member major-mode speedbar-ignored-modes)
  1599.                 (eq af speedbar-frame)
  1600.                 (not (buffer-file-name)))
  1601.             nil
  1602.               (if (<= 1 speedbar-verbosity-level)
  1603.               (message "Updating speedbar to: %s..."
  1604.                    default-directory))
  1605.               (speedbar-update-directory-contents)
  1606.               (if (<= 1 speedbar-verbosity-level)
  1607.               (message "Updating speedbar to: %s...done"
  1608.                    default-directory))))
  1609.           (select-frame af))
  1610.         ;; Now run stealthy updates of time-consuming items
  1611.         (speedbar-stealthy-updates))))
  1612.       ;; errors that might occur
  1613.       (error (message "Speedbar error!")))
  1614.     ;; Reset the timer
  1615.     (speedbar-set-timer speedbar-update-speed))
  1616.   (run-hooks 'speedbar-timer-hook)
  1617.   )
  1618.  
  1619.  
  1620. ;;; Stealthy activities
  1621. ;;
  1622. (defun speedbar-stealthy-updates ()
  1623.   "For a given speedbar, run all items in the stealthy function list.
  1624. Each item returns t if it completes successfully, or nil if
  1625. interrupted by the user."
  1626.   (let ((l speedbar-stealthy-function-list))
  1627.     (unwind-protect
  1628.     (while (and l (funcall (car l)))
  1629.       (sit-for 0)
  1630.       (setq l (cdr l)))
  1631.       ;(message "Exit with %S" (car l))
  1632.       )))
  1633.  
  1634. (defun speedbar-reset-scanners ()
  1635.   "Reset any variables used by functions in the stealthy list as state.
  1636. If new functions are added, their state needs to be updated here."
  1637.   (setq speedbar-vc-to-do-point t)
  1638.   )
  1639.  
  1640. (defun speedbar-clear-current-file ()
  1641.   "Locate the file thought to be current, and unhighlight it."
  1642.   (save-excursion
  1643.     (set-buffer speedbar-buffer)
  1644.     (if speedbar-last-selected-file
  1645.     (speedbar-with-writable
  1646.       (goto-char (point-min))
  1647.       (if (and
  1648.            speedbar-last-selected-file
  1649.            (re-search-forward
  1650.         (concat " \\(" (regexp-quote speedbar-last-selected-file)
  1651.             "\\)\\(" (regexp-quote speedbar-vc-indicator)
  1652.             "\\)?\n")
  1653.         nil t))
  1654.           (put-text-property (match-beginning 1)
  1655.                  (match-end 1)
  1656.                  'face
  1657.                  'speedbar-file-face))))))
  1658.  
  1659. (defun speedbar-update-current-file ()
  1660.   "Find the current file is, and update our visuals to indicate its name.
  1661. This is specific to file names.  If the file name doesn't show up, but
  1662. it should be in the list, then the directory cache needs to be
  1663. updated."
  1664.   (let* ((lastf (selected-frame))
  1665.      (newcfd (save-excursion
  1666.            (select-frame speedbar-attached-frame)
  1667.            (let ((rf (if (buffer-file-name)
  1668.                  (buffer-file-name)
  1669.                    nil)))
  1670.              (select-frame lastf)
  1671.              rf)))
  1672.      (newcf (if newcfd (file-name-nondirectory newcfd)))
  1673.      (lastb (current-buffer))
  1674.      (sucf-recursive (boundp 'sucf-recursive)))
  1675.     (if (and newcf
  1676.          ;; check here, that way we won't refresh to newcf until
  1677.          ;; its been written, thus saving ourselves some time
  1678.          (file-exists-p newcf)
  1679.          (not (string= newcf speedbar-last-selected-file)))
  1680.     (progn
  1681.       ;; It is important to select the frame, otherwise the window
  1682.       ;; we want the cursor to move in will not be updated by the
  1683.       ;; search-forward command.
  1684.       (select-frame speedbar-frame)
  1685.       ;; Remove the old file...
  1686.       (speedbar-clear-current-file)
  1687.       ;; now highlight the new one.
  1688.       (set-buffer speedbar-buffer)
  1689.       (speedbar-with-writable
  1690.         (goto-char (point-min))
  1691.         (if (re-search-forward
  1692.          (concat " \\(" (regexp-quote newcf) "\\)\\("
  1693.              (regexp-quote speedbar-vc-indicator)
  1694.              "\\)?\n") nil t)
  1695.           ;; put the property on it
  1696.           (put-text-property (match-beginning 1)
  1697.                      (match-end 1)
  1698.                      'face
  1699.                      'speedbar-selected-face)
  1700.           ;; Oops, it's not in the list.  Should it be?
  1701.           (if (and (string-match speedbar-file-regexp newcf)
  1702.                (string= (file-name-directory newcfd)
  1703.                 (expand-file-name default-directory)))
  1704.           ;; yes, it is (we will ignore unknowns for now...)
  1705.           (progn
  1706.             (speedbar-refresh)
  1707.             (if (re-search-forward
  1708.              (concat " \\(" (regexp-quote newcf) "\\)\n") nil t)
  1709.             ;; put the property on it
  1710.             (put-text-property (match-beginning 1)
  1711.                        (match-end 1)
  1712.                        'face
  1713.                        'speedbar-selected-face)))
  1714.         ;; if it's not in there now, whatever...
  1715.         ))
  1716.         (setq speedbar-last-selected-file newcf))
  1717.       (if (not sucf-recursive)
  1718.           (progn
  1719.         (forward-line -1)
  1720.         (speedbar-position-cursor-on-line)))
  1721.       (set-buffer lastb)
  1722.       (select-frame lastf)
  1723.       )))
  1724.   ;; return that we are done with this activity.
  1725.   t)
  1726.  
  1727. ;; If it's being used, check for it
  1728. (eval-when-compile (or (featurep 'xemacs) (require 'ange-ftp)))
  1729.  
  1730. (defun speedbar-check-vc ()
  1731.   "Scan all files in a directory, and for each see if it's checked out.
  1732. See `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p' for how
  1733. to add more types of version control systems."
  1734.   ;; Check for to-do to be reset.  If reset but no RCS is available
  1735.   ;; then set to nil (do nothing) otherwise, start at the beginning
  1736.   (save-excursion
  1737.     (set-buffer speedbar-buffer)
  1738.     (if (and speedbar-vc-do-check (eq speedbar-vc-to-do-point t)
  1739.          (speedbar-vc-check-dir-p default-directory)
  1740.          (not (and (featurep 'ange-ftp)
  1741.                (string-match (car
  1742.                       (if speedbar-xemacsp
  1743.                       ange-ftp-path-format
  1744.                     ange-ftp-name-format))
  1745.                      (expand-file-name default-directory)))))
  1746.     (setq speedbar-vc-to-do-point 0))
  1747.     (if (numberp speedbar-vc-to-do-point)
  1748.     (progn
  1749.       (goto-char speedbar-vc-to-do-point)
  1750.       (while (and (not (input-pending-p))
  1751.               (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] " nil t))
  1752.         (setq speedbar-vc-to-do-point (point))
  1753.         (if (speedbar-check-vc-this-line)
  1754.         (speedbar-with-writable
  1755.           (insert speedbar-vc-indicator))))
  1756.       (if (input-pending-p)
  1757.           ;; return that we are incomplete
  1758.           nil
  1759.         ;; we are done, set to-do to nil
  1760.         (setq speedbar-vc-to-do-point nil)
  1761.         ;; and return t
  1762.         t))
  1763.       t)))
  1764.  
  1765. (defun speedbar-check-vc-this-line ()
  1766.   "Return t if the file on this line is check of of a version control system.
  1767. The one caller-requirement is that the last regexp matching operation
  1768. has the current depth stored in (MATCHSTRING 1), and that the cursor
  1769. is right in front of the file name."
  1770.   (let* ((d (string-to-int (match-string 1)))
  1771.      (f (speedbar-line-path d))
  1772.      (fn (buffer-substring-no-properties
  1773.           (point) (progn (end-of-line) (point))))
  1774.      (fulln (concat f fn)))
  1775.     (if (<= 2 speedbar-verbosity-level)
  1776.     (message "Speedbar vc check...%s" fulln))
  1777.     (and (file-writable-p fulln)
  1778.      (speedbar-this-file-in-vc f fn))))
  1779.  
  1780. (defun speedbar-vc-check-dir-p (path)
  1781.   "Return t if we should bother checking PATH for version control files.
  1782. This can be overloaded to add new types of version control systems."
  1783.   (or
  1784.    (file-exists-p (concat path "RCS/"))
  1785.    ;; If SCCS is added in `speedbar-this-file-in-vc'
  1786.    ;; (file-exists-p (concat path "SCCS/"))
  1787.    ;; (file-exists-p (getenv "SCCSPATHTHINGIDONTREMEMBER"))
  1788.    ))
  1789.  
  1790. (defun speedbar-this-file-in-vc (path name)
  1791.   "Check to see if the file in PATH with NAME is in a version control system.
  1792. You can add new VC systems by overriding this function.  You can
  1793. optimize this function by overriding it and only doing those checks
  1794. that will occur on your system."
  1795.   (or
  1796.    (file-exists-p (concat path "RCS/" name ",v"))
  1797.    ;; Is this right?  I don't recall
  1798.    ;;(file-exists-p (concat path "SCCS/," fn))
  1799.    ;;(file-exists-p (concat (getenv "SCCSPATHTHING") "/SCCS/," fn))
  1800.    ))
  1801.  
  1802. ;;; Clicking Activity
  1803. ;;
  1804. (defun speedbar-quick-mouse (e)
  1805.   "Since mouse events are strange, this will keep the mouse nicely positioned.
  1806. This should be bound to mouse event E."
  1807.   (interactive "e")
  1808.   (mouse-set-point e)
  1809.   (speedbar-position-cursor-on-line)
  1810.   )
  1811.  
  1812. (defun speedbar-position-cursor-on-line ()
  1813.   "Position the cursor on a line."
  1814.   (let ((oldpos (point)))
  1815.     (beginning-of-line)
  1816.     (if (looking-at "[0-9]+:\\s-*..?.? ")
  1817.     (goto-char (1- (match-end 0)))
  1818.       (goto-char oldpos))))
  1819.  
  1820. (defun speedbar-power-click (e)
  1821.   "Activate any speedbar button as a power click.
  1822. This should be bound to mouse event E."
  1823.   (interactive "e")
  1824.   (let ((speedbar-power-click t))
  1825.     (speedbar-click e)))
  1826.  
  1827. (defun speedbar-click (e)
  1828.   "Activate any speedbar buttons where the mouse is clicked.
  1829. This must be bound to a mouse event.  A button is any location of text
  1830. with a mouse face that has a text property called `speedbar-function'.
  1831. This should be bound to mouse event E."
  1832.   (interactive "e")
  1833.   (mouse-set-point e)
  1834.   (speedbar-do-function-pointer)
  1835.   (speedbar-quick-mouse e))
  1836.  
  1837. (defun speedbar-do-function-pointer ()
  1838.   "Look under the cursor and examine the text properties.
  1839. From this extract the file/tag name, token, indentation level and call
  1840. a function if appropriate"
  1841.   (let* ((fn (get-text-property (point) 'speedbar-function))
  1842.      (tok (get-text-property (point) 'speedbar-token))
  1843.      ;; The 1-,+ is safe because scaning starts AFTER the point
  1844.      ;; specified.  This lets the search include the character the
  1845.      ;; cursor is on.
  1846.      (tp (previous-single-property-change
  1847.           (1+ (point)) 'speedbar-function))
  1848.      (np (next-single-property-change
  1849.           (point) 'speedbar-function))
  1850.      (txt (buffer-substring-no-properties (or tp (point-min))
  1851.                           (or np (point-max))))
  1852.      (dent (save-excursion (beginning-of-line)
  1853.                    (string-to-number
  1854.                 (if (looking-at "[0-9]+")
  1855.                     (buffer-substring-no-properties
  1856.                     (match-beginning 0) (match-end 0))
  1857.                   "0")))))
  1858.     ;;(message "%S:%S:%S:%s" fn tok txt dent)
  1859.     (and fn (funcall fn txt tok dent)))
  1860.   (speedbar-position-cursor-on-line))
  1861.  
  1862. ;;; Reading info from the speedbar buffer
  1863. ;;
  1864. (defun speedbar-line-file (&optional p)
  1865.   "Retrieve the file or whatever from the line at P point.
  1866. The return value is a string representing the file.  If it is a
  1867. directory, then it is the directory name."
  1868.   (save-excursion
  1869.     (save-match-data
  1870.       (beginning-of-line)
  1871.       (if (looking-at (concat
  1872.                "\\([0-9]+\\): *[[<][-+][]>] \\([^ \n]+\\)\\("
  1873.                (regexp-quote speedbar-vc-indicator)
  1874.                "\\)?"))
  1875.       (let* ((depth (string-to-int (match-string 1)))
  1876.          (path (speedbar-line-path depth))
  1877.          (f (match-string 2)))
  1878.         (concat path f))
  1879.     nil))))
  1880.  
  1881. (defun speedbar-goto-this-file (file)
  1882.   "If FILE is displayed, goto this line and return t.
  1883. Otherwise do not move and return nil."
  1884.   (let ((path (substring (file-name-directory (expand-file-name file))
  1885.              (length (expand-file-name default-directory))))
  1886.     (dest (point)))
  1887.     (save-match-data
  1888.       (goto-char (point-min))
  1889.       ;; scan all the directories
  1890.       (while (and path (not (eq path t)))
  1891.     (if (string-match "^/?\\([^/]+\\)" path)
  1892.         (let ((pp (match-string 1 path)))
  1893.           (if (save-match-data
  1894.             (re-search-forward (concat "> " (regexp-quote pp) "$")
  1895.                        nil t))
  1896.           (setq path (substring path (match-end 1)))
  1897.         (setq path nil)))
  1898.       (setq path t)))
  1899.       ;; find the file part
  1900.       (if (or (not path) (string= (file-name-nondirectory file) ""))
  1901.       ;; only had a dir part
  1902.       (if path
  1903.           (progn
  1904.         (speedbar-position-cursor-on-line)
  1905.         t)
  1906.         (goto-char dest) nil)
  1907.     ;; find the file part
  1908.     (let ((nd (file-name-nondirectory file)))
  1909.       (if (re-search-forward
  1910.            (concat "] \\(" (regexp-quote nd)
  1911.                "\\)\\(" (regexp-quote speedbar-vc-indicator) "\\)?$")
  1912.            nil t)
  1913.           (progn
  1914.         (speedbar-position-cursor-on-line)
  1915.         t)
  1916.         (goto-char dest)
  1917.         nil))))))
  1918.  
  1919. (defun speedbar-line-path (depth)
  1920.   "Retrieve the pathname associated with the current line.
  1921. This may require traversing backwards from DEPTH and combining the default
  1922. directory with these items."
  1923.   (save-excursion
  1924.     (save-match-data
  1925.       (let ((path nil))
  1926.     (setq depth (1- depth))
  1927.     (while (/= depth -1)
  1928.       (if (not (re-search-backward (format "^%d:" depth) nil t))
  1929.           (error "Error building path of tag")
  1930.         (cond ((looking-at "[0-9]+:\\s-*<->\\s-+\\([^\n]+\\)$")
  1931.            (setq path (concat (buffer-substring-no-properties
  1932.                        (match-beginning 1) (match-end 1))
  1933.                       "/"
  1934.                       path)))
  1935.           ((looking-at "[0-9]+:\\s-*[-]\\s-+\\([^\n]+\\)$")
  1936.            ;; This is the start of our path.
  1937.            (setq path (buffer-substring-no-properties
  1938.                    (match-beginning 1) (match-end 1))))))
  1939.       (setq depth (1- depth)))
  1940.     (if (and path
  1941.          (string-match (concat (regexp-quote speedbar-vc-indicator) "$")
  1942.                    path))
  1943.         (setq path (substring path 0 (match-beginning 0))))
  1944.     (concat default-directory path)))))
  1945.  
  1946. (defun speedbar-edit-line ()
  1947.   "Edit whatever tag or file is on the current speedbar line."
  1948.   (interactive)
  1949.   (save-excursion
  1950.     (beginning-of-line)
  1951.     ;; If this fails, then it is a non-standard click, and as such,
  1952.     ;; perfectly allowed.
  1953.     (re-search-forward "[]>}] [a-zA-Z0-9]"
  1954.                (save-excursion (end-of-line) (point)) t)
  1955.     (speedbar-do-function-pointer)))
  1956.  
  1957. (defun speedbar-expand-line ()
  1958.   "Expand the line under the cursor."
  1959.   (interactive)
  1960.   (beginning-of-line)
  1961.   (re-search-forward ":\\s-*.\\+. " (save-excursion (end-of-line) (point)))
  1962.   (forward-char -2)
  1963.   (speedbar-do-function-pointer))
  1964.  
  1965. (defun speedbar-contract-line ()
  1966.   "Contract the line under the cursor."
  1967.   (interactive)
  1968.   (beginning-of-line)
  1969.   (re-search-forward ":\\s-*.-. " (save-excursion (end-of-line) (point)))
  1970.   (forward-char -2)
  1971.   (speedbar-do-function-pointer))
  1972.  
  1973. (defun speedbar-maybee-jump-to-attached-frame ()
  1974.   "Jump to the attached frame ONLY if this was not a mouse event."
  1975.   (if (numberp last-input-char)
  1976.       (progn
  1977.     (select-frame speedbar-attached-frame)
  1978.     (other-frame 0))))
  1979.  
  1980. (defun speedbar-find-file (text token indent)
  1981.   "Speedbar click handler for filenames.
  1982. TEXT, the file will be displayed in the attached frame.
  1983. TOKEN is unused, but required by the click handler.  INDENT is the
  1984. current indentation level."
  1985.   (let ((cdd (speedbar-line-path indent)))
  1986.     (speedbar-find-file-in-frame (concat cdd text))
  1987.     (speedbar-stealthy-updates)
  1988.     ;; Reset the timer with a new timeout when cliking a file
  1989.     ;; in case the user was navigating directories, we can cancel
  1990.     ;; that other timer.
  1991.     (speedbar-set-timer speedbar-update-speed))
  1992.   (speedbar-maybee-jump-to-attached-frame))
  1993.  
  1994. (defun speedbar-dir-follow (text token indent)
  1995.   "Speedbar click handler for directory names.
  1996. Clicking a directory will cause the speedbar to list files in the
  1997. the subdirectory TEXT.  TOKEN is an unused requirement.  The
  1998. subdirectory chosen will be at INDENT level."
  1999.   (setq default-directory
  2000.     (concat (expand-file-name (concat (speedbar-line-path indent) text))
  2001.         "/"))
  2002.   ;; Because we leave speedbar as the current buffer,
  2003.   ;; update contents will change directory without
  2004.   ;; having to touch the attached frame.
  2005.   (speedbar-update-contents)
  2006.   (speedbar-set-timer speedbar-navigating-speed)
  2007.   (setq speedbar-last-selected-file nil)
  2008.   (speedbar-stealthy-updates))
  2009.  
  2010. (defun speedbar-delete-subblock (indent)
  2011.   "Delete text from point to indentation level INDENT or greater.
  2012. Handles end-of-sublist smartly."
  2013.   (speedbar-with-writable
  2014.     (save-excursion
  2015.       (end-of-line) (forward-char 1)
  2016.       (while (and (not (save-excursion
  2017.              (re-search-forward (format "^%d:" indent)
  2018.                         nil t)))
  2019.           (>= indent 0))
  2020.     (setq indent (1- indent)))
  2021.       (delete-region (point) (if (>= indent 0)
  2022.                  (match-beginning 0)
  2023.                    (point-max))))))
  2024.  
  2025. (defun speedbar-dired (text token indent)
  2026.   "Speedbar click handler for directory expand button.
  2027. Clicking this button expands or contracts a directory.  TEXT is the
  2028. button clicked which has either a + or -.  TOKEN is the directory to be
  2029. expanded.  INDENT is the current indentation level."
  2030.   (cond ((string-match "+" text)    ;we have to expand this dir
  2031.      (setq speedbar-shown-directories
  2032.            (cons (expand-file-name
  2033.               (concat (speedbar-line-path indent) token "/"))
  2034.              speedbar-shown-directories))
  2035.      (speedbar-change-expand-button-char ?-)
  2036.      (speedbar-reset-scanners)
  2037.      (save-excursion
  2038.        (end-of-line) (forward-char 1)
  2039.        (speedbar-with-writable
  2040.          (speedbar-default-directory-list
  2041.           (concat (speedbar-line-path indent) token "/")
  2042.           (1+ indent)))))
  2043.     ((string-match "-" text)    ;we have to contract this node
  2044.      (speedbar-reset-scanners)
  2045.      (let ((oldl speedbar-shown-directories)
  2046.            (newl nil)
  2047.            (td (expand-file-name
  2048.             (concat (speedbar-line-path indent) token))))
  2049.        (while oldl
  2050.          (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
  2051.          (setq newl (cons (car oldl) newl)))
  2052.          (setq oldl (cdr oldl)))
  2053.        (setq speedbar-shown-directories newl))
  2054.      (speedbar-change-expand-button-char ?+)
  2055.      (speedbar-delete-subblock indent)
  2056.      )
  2057.     (t (error "Ooops... not sure what to do.")))
  2058.   (speedbar-center-buffer-smartly)
  2059.   (setq speedbar-last-selected-file nil)
  2060.   (save-excursion (speedbar-stealthy-updates)))
  2061.  
  2062. (defun speedbar-directory-buttons-follow (text token indent)
  2063.   "Speedbar click handler for default directory buttons.
  2064. TEXT is the button clicked on.  TOKEN is the directory to follow.
  2065. INDENT is the current indentation level and is unused."
  2066.   (setq default-directory token)
  2067.   ;; Because we leave speedbar as the current buffer,
  2068.   ;; update contents will change directory without
  2069.   ;; having to touch the attached frame.
  2070.   (speedbar-update-contents)
  2071.   (speedbar-set-timer speedbar-navigating-speed))
  2072.  
  2073. (defun speedbar-tag-file (text token indent)
  2074.   "The cursor is on a selected line.  Expand the tags in the specified file.
  2075. The parameter TEXT and TOKEN are required, where TEXT is the button
  2076. clicked, and TOKEN is the file to expand.  INDENT is the current
  2077. indentation level."
  2078.   (cond ((string-match "+" text)    ;we have to expand this file
  2079.      (let* ((fn (expand-file-name (concat (speedbar-line-path indent)
  2080.                           token)))
  2081.         (lst (if speedbar-use-imenu-flag
  2082.             (let ((tim (speedbar-fetch-dynamic-imenu fn)))
  2083.               (if (eq tim t)
  2084.                   (speedbar-fetch-dynamic-etags fn)
  2085.                 tim))
  2086.               (speedbar-fetch-dynamic-etags fn))))
  2087.        ;; if no list, then remove expando button
  2088.        (if (not lst)
  2089.            (speedbar-change-expand-button-char ??)
  2090.          (speedbar-change-expand-button-char ?-)
  2091.          (speedbar-with-writable
  2092.            (save-excursion
  2093.          (end-of-line) (forward-char 1)
  2094.          (speedbar-insert-generic-list indent
  2095.                            lst 'speedbar-tag-expand
  2096.                            'speedbar-tag-find))))))
  2097.     ((string-match "-" text)    ;we have to contract this node
  2098.      (speedbar-change-expand-button-char ?+)
  2099.      (speedbar-delete-subblock indent))
  2100.     (t (error "Ooops... not sure what to do.")))
  2101.   (speedbar-center-buffer-smartly))
  2102.  
  2103. (defun speedbar-tag-find (text token indent)
  2104.   "For the tag TEXT in a file TOKEN, goto that position.
  2105. INDENT is the current indentation level."
  2106.   (let ((file (speedbar-line-path indent)))
  2107.     (speedbar-find-file-in-frame file)
  2108.     (save-excursion (speedbar-stealthy-updates))
  2109.     ;; Reset the timer with a new timeout when cliking a file
  2110.     ;; in case the user was navigating directories, we can cancel
  2111.     ;; that other timer.
  2112.     (speedbar-set-timer speedbar-update-speed)
  2113.     (goto-char token)
  2114.     ;;(recenter)
  2115.     (speedbar-maybee-jump-to-attached-frame)
  2116.     ))
  2117.  
  2118. (defun speedbar-tag-expand (text token indent)
  2119.   "Expand a tag sublist.  Imenu will return sub-lists of specialized tag types.
  2120. Etags does not support this feature.  TEXT will be the button
  2121. string.  TOKEN will be the list, and INDENT is the current indentation
  2122. level."
  2123.   (cond ((string-match "+" text)    ;we have to expand this file
  2124.      (speedbar-change-expand-button-char ?-)
  2125.      (speedbar-with-writable
  2126.        (save-excursion
  2127.          (end-of-line) (forward-char 1)
  2128.          (speedbar-insert-generic-list indent
  2129.                        token 'speedbar-tag-expand
  2130.                        'speedbar-tag-find))))
  2131.     ((string-match "-" text)    ;we have to contract this node
  2132.      (speedbar-change-expand-button-char ?+)
  2133.      (speedbar-delete-subblock indent))
  2134.     (t (error "Ooops... not sure what to do.")))
  2135.   (speedbar-center-buffer-smartly))
  2136.  
  2137. ;;; Loading files into the attached frame.
  2138. ;;
  2139. (defun speedbar-find-file-in-frame (file)
  2140.   "This will load FILE into the speedbar attached frame.
  2141. If the file is being displayed in a different frame already, then raise that
  2142. frame instead."
  2143.   (let* ((buff (find-file-noselect file))
  2144.      (bwin (get-buffer-window buff 0)))
  2145.     (if bwin
  2146.     (progn
  2147.       (select-window bwin)
  2148.       (raise-frame (window-frame bwin)))
  2149.       (if speedbar-power-click
  2150.       (let ((pop-up-frames t)) (select-window (display-buffer buff)))
  2151.     (select-frame speedbar-attached-frame)
  2152.     (switch-to-buffer buff))))
  2153.   )
  2154.  
  2155. ;;; Centering Utility
  2156. ;;
  2157. (defun speedbar-center-buffer-smartly ()
  2158.   "Recenter a speedbar buffer so the current indentation level is all visible.
  2159. This assumes that the cursor is on a file, or tag of a file which the user is
  2160. interested in."
  2161.   (if (<= (count-lines (point-min) (point-max))
  2162.       (window-height (selected-window)))
  2163.       ;; whole buffer fits
  2164.       (let ((cp (point)))
  2165.     (goto-char (point-min))
  2166.     (recenter 0)
  2167.     (goto-char cp))
  2168.     ;; too big
  2169.     (let (depth start end exp p)
  2170.       (save-excursion
  2171.     (beginning-of-line)
  2172.     (setq depth (if (looking-at "[0-9]+")
  2173.             (string-to-int (buffer-substring-no-properties
  2174.                     (match-beginning 0) (match-end 0)))
  2175.               0))
  2176.     (setq exp (format "^%d:\\s-*[[{<]\\([?+-]\\)[]>}]" depth)))
  2177.       (save-excursion
  2178.     (end-of-line)
  2179.     (if (re-search-backward exp nil t)
  2180.         (setq start (point))
  2181.       (error "Center error"))
  2182.     (save-excursion            ;Not sure about this part.
  2183.       (end-of-line)
  2184.       (setq p (point))
  2185.       (while (and (not (re-search-forward exp nil t))
  2186.               (>= depth 0))
  2187.         (setq depth (1- depth))
  2188.         (setq exp (format "^%d:\\s-*[[{<]\\([?+-]\\)[]>}]" depth)))
  2189.       (if (/= (point) p)
  2190.           (setq end (point))
  2191.         (setq end (point-max)))))
  2192.       ;; Now work out the details of centering
  2193.       (let ((nl (count-lines start end))
  2194.         (cp (point)))
  2195.     (if (> nl (window-height (selected-window)))
  2196.         ;; We can't fit it all, so just center on cursor
  2197.         (progn (goto-char start)
  2198.            (recenter 1))
  2199.       ;; we can fit everything on the screen, but...
  2200.       (if (and (pos-visible-in-window-p start (selected-window))
  2201.            (pos-visible-in-window-p end (selected-window)))
  2202.           ;; we are all set!
  2203.           nil
  2204.         ;; we need to do something...
  2205.         (goto-char start)
  2206.         (let ((newcent (/ (- (window-height (selected-window)) nl) 2))
  2207.           (lte (count-lines start (point-max))))
  2208.           (if (and (< (+ newcent lte) (window-height (selected-window)))
  2209.                (> (- (window-height (selected-window)) lte 1)
  2210.               newcent))
  2211.           (setq newcent (- (window-height (selected-window))
  2212.                    lte 1)))
  2213.           (recenter newcent))))
  2214.     (goto-char cp)))))
  2215.  
  2216.  
  2217. ;;; Tag Management -- Imenu
  2218. ;;
  2219. (if  (string-match "XEmacs" emacs-version)
  2220.  
  2221.     nil
  2222.  
  2223. (eval-when-compile (if (locate-library "imenu") (require 'imenu)))
  2224.  
  2225. (defun speedbar-fetch-dynamic-imenu (file)
  2226.   "Load FILE into a buffer, and generate tags using Imenu.
  2227. Returns the tag list, or t for an error."
  2228.   ;; Load this AND compile it in
  2229.   (require 'imenu)
  2230.   (save-excursion
  2231.     (set-buffer (find-file-noselect file))
  2232.     (condition-case nil
  2233.     (progn
  2234.       (if speedbar-power-click (setq imenu--index-alist nil))
  2235.       (imenu--make-index-alist t))
  2236.       (error t))))
  2237. )
  2238.  
  2239. ;;; Tag Management -- etags  (XEmacs compatibility part)
  2240. ;;
  2241. (defvar speedbar-fetch-etags-parse-list
  2242.   '(;; Note that java has the same parse-group as c
  2243.     ("\\.\\([cChH]\\|c\\+\\+\\|cpp\\|cc\\|hh\\|java\\)$" . speedbar-parse-c-or-c++tag)
  2244.     ("\\.el\\|\\.emacs" . "defun\\s-+\\(\\(\\w\\|[-_]\\)+\\)\\s-*\C-?")
  2245.     ("\\.tex$" . speedbar-parse-tex-string)
  2246.     ("\\.p" .
  2247.      "\\(\\(FUNCTION\\|function\\|PROCEDURE\\|procedure\\)\\s-+\\([a-zA-Z0-9_.:]+\\)\\)\\s-*(?^?")
  2248.  
  2249.     )
  2250.   "Associations of file extensions and expressions for extracting tags.
  2251. To add a new file type, you would want to add a new association to the
  2252. list, where the car is the file match, and the cdr is the way to
  2253. extract an element from the tags output.  If the output is complex,
  2254. use a function symbol instead of regexp.  The function should expect
  2255. to be at the beginning of a line in the etags buffer.
  2256.  
  2257. This variable is ignored if `speedbar-use-imenu-flag' is t")
  2258.  
  2259. (defvar speedbar-fetch-etags-command "etags"
  2260.   "*Command used to create an etags file.
  2261.  
  2262. This variable is ignored if `speedbar-use-imenu-flag' is t")
  2263.  
  2264. (defvar speedbar-fetch-etags-arguments '("-D" "-I" "-o" "-")
  2265.   "*List of arguments to use with `speedbar-fetch-etags-command'.
  2266. This creates an etags output buffer.  Use `speedbar-toggle-etags' to
  2267. modify this list conveniently.
  2268.  
  2269. This variable is ignored if `speedbar-use-imenu-flag' is t")
  2270.  
  2271. (defun speedbar-toggle-etags (flag)
  2272.   "Toggle FLAG in `speedbar-fetch-etags-arguments'.
  2273. FLAG then becomes a member of etags command line arguments.  If flag
  2274. is \"sort\", then toggle the value of `speedbar-sort-tags'.  If it's
  2275. value is \"show\" then toggle the value of
  2276. `speedbar-show-unknown-files'.
  2277.  
  2278.   This function is a convenience function for XEmacs menu created by
  2279. Farzin Guilak <farzin@protocol.com>"
  2280.   (interactive)
  2281.   (cond
  2282.    ((equal flag "sort")
  2283.     (setq speedbar-sort-tags (not speedbar-sort-tags)))
  2284.    ((equal flag "show")
  2285.     (setq speedbar-show-unknown-files (not speedbar-show-unknown-files)))
  2286.    ((or (equal flag "-C")
  2287.     (equal flag "-S")
  2288.     (equal flag "-D"))
  2289.     (if (member flag speedbar-fetch-etags-arguments)
  2290.     (setq speedbar-fetch-etags-arguments
  2291.           (delete flag speedbar-fetch-etags-arguments))
  2292.       (add-to-list 'speedbar-fetch-etags-arguments flag)))
  2293.    (t nil)))
  2294.  
  2295. (defun speedbar-fetch-dynamic-etags (file)
  2296.   "For FILE, run etags and create a list of symbols extracted.
  2297. Each symbol will be associated with it's line position in FILE."
  2298.   (let ((newlist nil))
  2299.     (unwind-protect
  2300.     (save-excursion
  2301.       (if (get-buffer "*etags tmp*")
  2302.           (kill-buffer "*etags tmp*"))    ;kill to clean it up
  2303.       (if (<= 1 speedbar-verbosity-level) (message "Fetching etags..."))
  2304.       (set-buffer (get-buffer-create "*etags tmp*"))
  2305.       (apply 'call-process speedbar-fetch-etags-command nil
  2306.          (current-buffer) nil
  2307.          (append speedbar-fetch-etags-arguments (list file)))
  2308.       (goto-char (point-min))
  2309.       (if (<= 1 speedbar-verbosity-level) (message "Fetching etags..."))
  2310.       (let ((expr
  2311.          (let ((exprlst speedbar-fetch-etags-parse-list)
  2312.                (ans nil))
  2313.            (while (and (not ans) exprlst)
  2314.              (if (string-match (car (car exprlst)) file)
  2315.              (setq ans (car exprlst)))
  2316.              (setq exprlst (cdr exprlst)))
  2317.            (cdr ans))))
  2318.         (if expr
  2319.         (let (tnl)
  2320.           (while (not (save-excursion (end-of-line) (eobp)))
  2321.             (save-excursion
  2322.               (setq tnl (speedbar-extract-one-symbol expr)))
  2323.             (if tnl (setq newlist (cons tnl newlist)))
  2324.             (forward-line 1)))
  2325.           (message "Sorry, no support for a file of that extension"))))
  2326.       )
  2327.     (if speedbar-sort-tags
  2328.     (sort newlist (lambda (a b) (string< (car a) (car b))))
  2329.       (reverse newlist))))
  2330.  
  2331. ;; This bit donated by Farzin Guilak <farzin@protocol.com> but I'm not
  2332. ;; sure it's needed with the different sorting method.
  2333. ;;
  2334. ;(defun speedbar-clean-etags()
  2335. ;  "Removes spaces before the ^? character, and removes `#define',
  2336. ;return types, etc. preceding tags.  This ensures that the sort operation
  2337. ;works on the tags, not the return types."
  2338. ;  (save-excursion
  2339. ;    (goto-char (point-min))
  2340. ;    (while
  2341. ;    (re-search-forward "(?[ \t](?\C-?" nil t)
  2342. ;      (replace-match "\C-?" nil nil))
  2343. ;    (goto-char (point-min))
  2344. ;    (while
  2345. ;    (re-search-forward "\\(.*[ \t]+\\)\\([^ \t\n]+.*\C-?\\)" nil t)
  2346. ;      (delete-region (match-beginning 1) (match-end 1)))))
  2347.  
  2348. (defun speedbar-extract-one-symbol (expr)
  2349.   "At point, return nil, or one alist in the form: ( symbol . position )
  2350. The line should contain output from etags.  Parse the output using the
  2351. regular expression EXPR"
  2352.   (let* ((sym (if (stringp expr)
  2353.           (if (save-excursion
  2354.             (re-search-forward expr (save-excursion
  2355.                           (end-of-line)
  2356.                           (point)) t))
  2357.               (buffer-substring-no-properties (match-beginning 1)
  2358.                               (match-end 1)))
  2359.         (funcall expr)))
  2360.      (pos (let ((j (re-search-forward "[\C-?\C-a]\\([0-9]+\\),\\([0-9]+\\)"
  2361.                       (save-excursion
  2362.                         (end-of-line)
  2363.                         (point))
  2364.                       t)))
  2365.         (if (and j sym)
  2366.             (1+ (string-to-int (buffer-substring-no-properties
  2367.                     (match-beginning 2)
  2368.                     (match-end 2))))
  2369.           0))))
  2370.     (if (/= pos 0)
  2371.     (cons sym pos)
  2372.       nil)))
  2373.  
  2374. (defun speedbar-parse-c-or-c++tag ()
  2375.   "Parse a c or c++ tag, which tends to be a little complex."
  2376.   (save-excursion
  2377.     (let ((bound (save-excursion (end-of-line) (point))))
  2378.       (cond ((re-search-forward "\C-?\\([^\C-a]+\\)\C-a" bound t)
  2379.          (buffer-substring-no-properties (match-beginning 1)
  2380.                          (match-end 1)))
  2381.         ((re-search-forward "\\<\\([^ \t]+\\)\\s-+new(" bound t)
  2382.          (buffer-substring-no-properties (match-beginning 1)
  2383.                          (match-end 1)))
  2384.         ((re-search-forward "\\<\\([^ \t(]+\\)\\s-*(\C-?" bound t)
  2385.          (buffer-substring-no-properties (match-beginning 1)
  2386.                          (match-end 1)))
  2387.         (t nil))
  2388.       )))
  2389.  
  2390. (defun speedbar-parse-tex-string ()
  2391.   "Parse a Tex string.  Only find data which is relevant."
  2392.   (save-excursion
  2393.     (let ((bound (save-excursion (end-of-line) (point))))
  2394.       (cond ((re-search-forward "\\(section\\|chapter\\|cite\\)\\s-*{[^\C-?}]*}?" bound t)
  2395.          (buffer-substring-no-properties (match-beginning 0)
  2396.                          (match-end 0)))
  2397.         (t nil)))))
  2398.  
  2399.  
  2400. ;;; Color loading section  This is messy *Blech!*
  2401. ;;
  2402. (defun speedbar-load-color (sym l-fg l-bg d-fg d-bg &optional bold italic underline)
  2403.   "Create a color for SYM with a L-FG and L-BG color, or D-FG and D-BG.
  2404. Optionally make BOLD, ITALIC, or UNDERLINE if applicable.  If the background
  2405. attribute of the current frame is determined to be light (white, for example)
  2406. then L-FG and L-BG is used.  If not, then D-FG and D-BG is used.  This will
  2407. allocate the colors in the best possible manor.  This will allow me to store
  2408. multiple defaults and dynamically determine which colors to use."
  2409.   (let* ((params (frame-parameters))
  2410.      (disp-res (if (fboundp 'x-get-resource)
  2411.                (if speedbar-xemacsp
  2412.                (x-get-resource ".displayType" "DisplayType" 'string)
  2413.              (x-get-resource ".displayType" "DisplayType"))
  2414.              nil))
  2415.      (display-type
  2416.       (cond (disp-res (intern (downcase disp-res)))
  2417.         ((and (fboundp 'x-display-color-p) (x-display-color-p)) 'color)
  2418.         (t 'mono)))
  2419.      (bg-res (if (fboundp 'x-get-resource)
  2420.              (if speedbar-xemacsp
  2421.              (x-get-resource ".backgroundMode" "BackgroundMode" 'string)
  2422.                (x-get-resource ".backgroundMode" "BackgroundMode"))
  2423.            nil))
  2424.      (bgmode
  2425.       (cond (bg-res (intern (downcase bg-res)))
  2426.         ((let* ((bgc (or (cdr (assq 'background-color params))
  2427.                  (if speedbar-xemacsp
  2428.                      (x-get-resource ".background"
  2429.                              "Background" 'string)
  2430.                    (x-get-resource ".background"
  2431.                            "Background"))
  2432.                  ;; if no other options, default is white
  2433.                  "white"))
  2434.             (bgcr (if speedbar-xemacsp
  2435.                   (color-instance-rgb-components
  2436.                    (make-color-instance bgc))
  2437.                 (x-color-values bgc)))
  2438.             (wcr (if speedbar-xemacsp
  2439.                  (color-instance-rgb-components
  2440.                   (make-color-instance "white"))
  2441.                    (x-color-values "white"))))
  2442.            (< (apply '+ bgcr) (/ (apply '+ wcr) 3)))
  2443.          'dark)
  2444.         (t 'light)))        ;our default
  2445.      (set-p (function (lambda (face-name resource)
  2446.                 (if speedbar-xemacsp
  2447.                 (x-get-resource
  2448.                  (concat face-name ".attribute" resource)
  2449.                  (concat "Face.Attribute" resource)
  2450.                  'string)
  2451.                   (x-get-resource
  2452.                    (concat face-name ".attribute" resource)
  2453.                    (concat "Face.Attribute" resource)))
  2454.                 )))
  2455.      (nbg (cond ((eq bgmode 'dark) d-bg)
  2456.             (t l-bg)))
  2457.      (nfg (cond ((eq bgmode 'dark) d-fg)
  2458.             (t l-fg))))
  2459.  
  2460.     (if (not (eq display-type 'color))
  2461.     ;; we need a face of some sort, so just make due with default
  2462.     (progn
  2463.       (copy-face 'default sym)
  2464.       (if bold (condition-case nil
  2465.                (make-face-bold sym)
  2466.              (error (message "Cannot make face %s bold!"
  2467.                      (symbol-name sym)))))
  2468.       (if italic (condition-case nil
  2469.              (make-face-italic sym)
  2470.                (error (message "Cannot make face %s italic!"
  2471.                        (symbol-name sym)))))
  2472.       (set-face-underline-p sym underline)
  2473.       )
  2474.       ;; make a colorized version of a face.  Be sure to check Xdefaults
  2475.       ;; for possible overrides first!
  2476.       (let ((newface (make-face sym)))
  2477.     ;; For each attribute, check if it might already be set by Xdefaults
  2478.     (if (and nfg (not (funcall set-p (symbol-name sym) "Foreground")))
  2479.         (set-face-foreground newface nfg))
  2480.     (if (and nbg (not (funcall set-p (symbol-name sym) "Background")))
  2481.         (set-face-background newface nbg))
  2482.  
  2483.     (if bold (condition-case nil
  2484.              (make-face-bold newface)
  2485.            (error (message "Cannot make face %s bold!"
  2486.                        (symbol-name sym)))))
  2487.     (if italic (condition-case nil
  2488.                (make-face-italic newface)
  2489.              (error (message "Cannot make face %s italic!"
  2490.                      (symbol-name newface)))))
  2491.     (set-face-underline-p newface underline)
  2492.     ))))
  2493.  
  2494. (if (x-display-color-p)
  2495.     (progn
  2496.       (speedbar-load-color 'speedbar-button-face "green4" nil "green3" nil nil nil nil)
  2497.       (speedbar-load-color 'speedbar-file-face "cyan4" nil "cyan" nil nil nil nil)
  2498.       (speedbar-load-color 'speedbar-directory-face "blue4" nil "light blue" nil nil nil nil)
  2499.       (speedbar-load-color 'speedbar-tag-face "brown" nil "yellow" nil nil nil nil)
  2500.       (speedbar-load-color 'speedbar-selected-face "red" nil "red" nil nil nil t)
  2501.       (speedbar-load-color 'speedbar-highlight-face nil "green" nil "sea green" nil nil nil)
  2502.       ) ; color
  2503.   (make-face 'speedbar-button-face)
  2504.   ;;(make-face 'speedbar-file-face)
  2505.   (copy-face 'bold 'speedbar-file-face)
  2506.   (make-face 'speedbar-directory-face)
  2507.   (make-face 'speedbar-tag-face)
  2508.   ;;(make-face 'speedbar-selected-face)
  2509.   (copy-face 'underline 'speedbar-selected-face)
  2510.   ;;(make-face 'speedbar-highlight-face)
  2511.   (copy-face 'highlight 'speedbar-highlight-face)
  2512.  
  2513.   ) ;; monochrome
  2514.  
  2515. ;; some edebug hooks
  2516. (add-hook 'edebug-setup-hook
  2517.       (lambda ()
  2518.         (def-edebug-spec speedbar-with-writable def-body)))
  2519.  
  2520. ;; run load-time hooks
  2521. (run-hooks 'speedbar-load-hook)
  2522.  
  2523. (provide 'speedbar)
  2524. ;;; speedbar ends here
  2525.